问题描述
(删除 system-site-packagespip uninstall
不再适用于较新版本的 virtualenv)
(removing system-site-packages with pip uninstall
does no longer work for newer versions of virtualenv)
另一种方法是创建一个干净的 virtualenv 并链接您需要的部分:
Another way would be to create a clean virtualenv and link the parts that you need:
$ virtualenv --no-site-packages foo
$ source foo/bin/activate
$ ln -s /usr/lib/python2.7/dist-packages/PIL* $VIRTUAL_ENV/lib/python*/site-packages
这些命令在非 unixish 环境中可能略有不同.路径还取决于您使用的系统.为了找出库的路径,启动python shell(没有激活的virtualenv),导入模块并检查module_name.__path__
.例如
The commands might be slightly different on a non-unixish environment. The paths also depend on the system you are using. In order to find out the path to the library start up the python shell (without an activated virtualenv), import the module and check module_name.__path__
. e.g.
Python 2.7.3 (default, Sep 26 2012, 21:51:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
>>> PIL.__path__
['/usr/lib/python2.7/dist-packages/PIL']
此外,如果您使用 --system-site-packages
创建了 virtualenv,则可以使用 pip install --upgrade -- 安装比系统中的版本更新的版本忽略安装的 numpy
.
Also if you have created your virtualenv with --system-site-packages
, it is possible to install newer version than what is in the system with pip install --upgrade --ignore-installed numpy
.
这篇关于virtualenv:指定在系统范围和本地使用哪些包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!