virtualenv 可以从另一个继承吗? [英] Can a virtualenv inherit from another?
问题描述
我想创建一个 virtualenv
使用另一个作为起点,这可能吗?
I want to create one virtualenv
using another as the starting point, is this possible?
我必须牢记用例:
假设我有两个
virtualenv
一个用于生产,一个用于开发.开发环境需要与生产环境相同的包,但它需要生产环境中我不想要的其他包.我不想安装公共包两次.
Let's say I have a two
virtualenv
one for production and one for development. The development environment requires the same packages as the production environment, but it requires others I don't want in the production environment. I don't want to install the common packages twice.
我想试验一个包的开发版本,例如 matplotlib
.包的开发版与稳定版的要求相同.所以我创建了一个名为 matplotib_stable
的 virtualenv
并安装了需求和稳定版本.然后我创建了一个名为 matplotlib_dev
的第二个 virtualenv
并使用 matplotlib_stable
作为起点(对于 matplotlib
要求)但是然后我安装开发版本.
I want to experiment with a development version of a package, say matplotlib
for example. The development version of the package has the same requirements as the stable version. So I create a virtualenv
called matplotib_stable
and install the requirements and the stable version. Then I create a second virtualenv
called matplotlib_dev
and use matplotlib_stable
as a starting point (for the matplotlib
requirements) but then I install the development version.
如何从本地缓存安装pip? 似乎解决了下载包的问题,但我不认为它涉及修改 sys.path
.
How do I install from a local cache with pip? seems to address the issue of downloading packages, but I don't think it deals with modifying sys.path
.
推荐答案
一种解决方案是使用 virtualenvwrapper
的 add2virtualenv
命令.这个
One solution is to use virtualenvwrapper
's add2virtualenv
command. This
将指定的目录添加到 Python 路径中当前处于活动状态的 virtualenv.
Adds the specified directories to the Python path for the currently-active virtualenv.
因此,如果我有两个 virtualenv
,ENV1
和 ENV2
,并且我希望 ENV2
访问这些包在 ENV1
中,那么我需要:
So if I have two virtualenv
, ENV1
and ENV2
, and I want ENV2
to access the packages in ENV1
, then I need to:
激活
ENV2
:
处理 ENV2
使用add2virtualenv
添加ENV1
的site-packages目录:
add ENV1
's site-packages directory using add2virtualenv
:
add2virtualenv $WORKON_HOME/ENV1/lib/python2.6/site-packages
以上假设 $WORKON_HOME
是您的 virtualenv 目录的位置,并且您使用的是 python2.6,因此显然要相应地调整它们.
The above assumes $WORKON_HOME
is the location of your virtualenv directories, and that you are using python2.6, so obviously adjust those accordingly.
虽然这提供了对包的访问,但它不会调整 shell 路径.换句话说,使用此方法无法访问安装到 bin
目录的脚本.
While this provides access to the packages it does not adjust the shell path. In other words, scripts installed to the bin
directory are not accessible using this method.
这篇关于virtualenv 可以从另一个继承吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!