如何将模块从一个virtualenv复制到另一个 [英] how to copy modules from one virtualenv to another
问题描述
是否可以将python模块从一个virtualenv复制到另一个虚拟机。如何完成?
当您将他们从一个虚拟机移动到另一个相同的机器时,您可以轻松地执行以下操作:
$ cp -r [env1] /lib/pythonX.X/site-packages/* [env2] /lib/pythonX.X/site-packages/
$但是,如果环境位于不同的机器上,或者使用不同版本的python或其他重大差异,那可能不是一个好主意。一般来说,生成
requires.txt
更安全,然后使用它来加载其他环境中的所有相同的模块。如果您愿意,可以手动创建文件,但使用pip
更容易。$ pip freeze -E [env1]>或者,如果您的virtualenv已经被激活,您可以简单地:
$ pip freeze>要求.txt
然后,在您的其他环境中,您可以执行以下操作:
$ pip install -E [env2] -r /path/to/requirements.txt
Is it possibe to copy python modules from one virtualenv to another.If so how is this done?
解决方案As long as you're moving them from one virtualenv to another on the same machine, you could easily just do:
$ cp -r [env1]/lib/pythonX.X/site-packages/* [env2]/lib/pythonX.X/site-packages/
However, if the environments are on different machines or utilizing different versions of python or some other major difference, it's probably not a good idea. In general it's much safer to generate a
requirements.txt
, and then use that to load up all the same modules in the other environment. You can create the file manually if you like, but it's easier to just usepip
.$ pip freeze -E [env1] > requirements.txt
Or, if your virtualenv is activated already, you can simply do:
$ pip freeze > requirements.txt
Then, in your other environment, you can do:
$ pip install -E [env2] -r /path/to/requirements.txt
这篇关于如何将模块从一个virtualenv复制到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!