最简单的方法是创建一个包含系统站点包的 virtualenv,然后安装您需要的版本:
$ virtualenv --system-site-packages foo
$ source foo/bin/activate
$ pip install Django==1.4.3
You can also clean up the virtualenv afterwards by checking the output of pip freeze
and removing the packages that you do not want. (removing system-site-packages with pip uninstall
does no longer work for newer versions of virtualenv)
另一种方法是创建一个干净的 virtualenv 并链接您需要的部分:
$ 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__
. 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']
另外,如果您使用以下命令创建了 virtualenv--system-site-packages
,可以安装比系统中更新的版本pip install --upgrade --ignore-installed numpy
.