使virtualenv继承全局站点程序包中的特定程序包

问题:使virtualenv继承全局站点程序包中的特定程序包

我正在寻找一种制作virtualenv的方法,该方法只包含基本python安装的一些库(我选择了这些库)。

更具体地说,我正在尝试在创建virtualenv的过程中将matplotlib导入virtualenv。由于缺少某些fortran编译器库,因此无法使用pip或easy_install有效安装。我到目前为止的方法是手动从

/usr/lib/python2.7/dist-packages/ to virtualenv_name/lib/python2.7/dist-packages/

但是,这会阻止手动导入的链接被蛋黄注册(这会在virtualenv中打印所有当前可用的库)。

因此,有没有一种方法可以对

virtualenv --system-site-packages

I’m looking for a way to make a virtualenv which will contain just some libraries (which i chose) of the base python installation.

To be more concrete, I’m trying to import my matplotlib to virtualenv during the creation of virtualenv. It can’t be installed efficiently with pip or easy_install since it misses some fortran compiler libs. The way i did it till now was to manually copy from

/usr/lib/python2.7/dist-packages/ to virtualenv_name/lib/python2.7/dist-packages/

however this prevents the manully imported links to be registerd by yolk (which prints all currently available libs in virtualenv).

So, is there a way to do a selective variant of the

virtualenv --system-site-packages

回答 0

用创建环境virtualenv --system-site-packages。然后,激活virtualenv,并在将其安装在virtualenv中而不是系统python中时,请使用pip install --ignore-installedpip install -I。这样,即使存在系统范围的版本,pip也会在本地安装您所请求的内容。您的python解释器将首先在virtualenv的package目录中查找,因此这些程序包应覆盖全局程序包。

Create the environment with virtualenv --system-site-packages . Then, activate the virtualenv and when you want things installed in the virtualenv rather than the system python, use pip install --ignore-installed or pip install -I . That way pip will install what you’ve requested locally even though a system-wide version exists. Your python interpreter will look first in the virtualenv’s package directory, so those packages should shadow the global ones.


回答 1

您可以使用--system-site-packages,然后“过度安装”您的virtualenv特定的东西。这样,您安装到virtualenv中的所有内容都将从此处获取,否则将从系统中获取。

You can use the --system-site-packages and then “overinstall” the specific stuff for your virtualenv. That way, everything you install into your virtualenv will be taken from there, otherwise it will be taken from your system.


回答 2

使用安装虚拟环境

virtualenv --system-site-packages

和使用 pip install -U to install matplotlib

Install virtual env with

virtualenv --system-site-packages

and use pip install -U to install matplotlib


回答 3

您可以使用virtualenv --clear。不会安装任何软件包,然后安装所需的软件包。

You can use virtualenv --clear. which won’t install any packages, then install the ones you want.