让 virtualenv 从你的全局站点包中继承特定的包 [英] Make virtualenv inherit specific packages from your global site-packages

查看:95
本文介绍了让 virtualenv 从你的全局站点包中继承特定的包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法来制作一个仅包含基本 python 安装的一些库(我选择的)的 virtualenv.

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

更具体地说,我试图在创建 virtualenv 期间将我的 matplotlib 导入到 virtualenv.它无法使用 pip 或 easy_install 有效安装,因为它缺少一些 fortran 编译器库.我到现在为止的做法是手动复制

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/

然而,这会阻止手动导入的链接被 yolk 注册(它会打印 virtualenv 中所有当前可用的库).

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

推荐答案

使用 virtualenv --system-site-packages 创建环境.然后,激活 virtualenv 并且当您希望将东西安装在 virtualenv 而不是系统 python 中时,使用 pip install --ignore-installedpip install -I .这样,即使存在系统范围的版本,pip 也会安装您在本地请求的内容.您的 Python 解释器将首先查看 virtualenv 的包目录,因此这些包应该隐藏全局包.

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.

这篇关于让 virtualenv 从你的全局站点包中继承特定的包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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