问题描述
我是virtualenv的新手,但是我正在编写django应用程序,最后我将不得不以某种方式进行部署。
I'm new to virtualenv but I'm writting django app and finally I will have to deploy it somehow.
因此,假设我的应用程序正在开发中我在其中安装所有必需库的本地virtualenv。我现在想做的是运行某种脚本,该脚本将带走我的virtualenv,检查其中安装了什么,并生成一个脚本,将所有这些库安装在另一台计算机上的最新virtualenv上。如何做到这一点?请帮忙。
So lets assume I have my app working on my local virtualenv where I installed all the required libraries. What I want to do now, is to run some kind of script, that will take my virtualenv, check what's installed inside and produce a script that will install all these libraries on fresh virtualenv on other machine. How this can be done? Please help.
推荐答案
您不复制粘贴您的virtualenv。您导出所有已安装软件包的列表,例如-
You don't copy paste your virtualenv. You export the list of all the packages installed like -
pip freeze > requirements.txt
然后推送 requirements.txt
将文件存储到您想要部署代码的任何位置,然后只需在开发机上做您的工作-
Then push the requirements.txt
file to anywhere you want to deploy the code, and then just do what you did on dev machine -
$ virtualenv <env_name>
$ source <env_name>/bin/activate
(<env_name>)$ pip install -r path/to/requirements.txt
在那里,您已经安装了具有正确版本的所有软件包。
And there you have all your packages installed with the exact version.
您还可以查看使用以下功能自动执行此任务-
You can also look into Fabric to automate this task, with a function like this -
def pip_install():
with cd(env.path):
with prefix('source venv/bin/activate'):
run('pip install -r requirements.txt')
这篇关于如何导出virtualenv?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!