如何将模块从一个 virtualenv 复制到另一个 [英] how to copy modules from one virtualenv to another

查看:35
本文介绍了如何将模块从一个 virtualenv 复制到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将 python 模块从一个 virtualenv 复制到另一个 virtualenv.如果可以,这是如何完成的?

Is it possibe to copy python modules from one virtualenv to another.If so how is this done?

推荐答案

只要您将它们从一个 virtualenv 移动到 同一 台机器上的另一个虚拟环境,您就可以轻松做到:

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/

然而,如果环境在不同的机器上或使用不同版本的 python 或其他一些主要差异,这可能不是一个好主意.一般来说,生成一个 requirements.txt 会更安全,然后使用它在其他环境中加载所有相同的模块.如果您愿意,您可以手动创建文件,但使用 pip 更容易.

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 use pip.

$ pip freeze -E [env1] > requirements.txt

或者,如果您的 virtualenv 已经被激活,您可以简单地执行:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆