Python 如何导出virtualenv?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14684968/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to export virtualenv?
提问by mnowotka
I'm new to virtualenv but I'm writting django app and finally I will have to deploy it somehow.
我是 virtualenv 的新手,但我正在编写 django 应用程序,最后我将不得不以某种方式部署它。
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 上运行。我现在想要做的是运行某种脚本,它将使用我的 virtualenv,检查内部安装的内容并生成一个脚本,该脚本将在其他机器上的新 virtualenv 上安装所有这些库。如何做到这一点?请帮忙。
采纳答案by Bibhas Debnath
You don't copy paste your virtualenv. You export the list of all the packages installed like -
您不要复制粘贴您的 virtualenv。您导出所有已安装软件包的列表,例如 -
pip freeze > requirements.txt
Then push the requirements.txtfile to anywhere you want to deploy the code, and then just do what you did on dev machine -
然后将requirements.txt文件推送到您想要部署代码的任何位置,然后执行您在开发机器上所做的操作 -
$ 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 Fabricto automate this task, with a function like this -
您还可以查看Fabric以自动执行此任务,具有这样的功能 -
def pip_install():
with cd(env.path):
with prefix('source venv/bin/activate'):
run('pip install -r requirements.txt')
回答by Sigurdur Torfinnur Einarsson
If it is going to be on the same path you can tar it and extract it on another machine. If all the same dependencies, libraries etc are available on the target machine it will work.
如果它将在同一路径上,您可以对其进行 tar 并在另一台机器上提取它。如果目标机器上有所有相同的依赖项、库等,它就会工作。
回答by Shon
You can install virtualenvwrapper and try cpvirtualenv, but the developers advise caution here:
您可以安装 virtualenvwrapper 并尝试cpvirtualenv,但开发人员建议谨慎使用:
Warning
Copying virtual environments is not well supported. Each virtualenv has path information hard-coded into it, and there may be cases where the copy code does not know it needs to update a particular file. Use with caution.
警告
不能很好地支持复制虚拟环境。每个 virtualenv 都有硬编码的路径信息,并且可能存在复制代码不知道它需要更新特定文件的情况。谨慎使用。

