Virtualenv不隔离pip在Ubuntu上正确安装

我在Ubuntu 12上使用virtualenv,当我使用pip安装软件包(在激活virtualenv之后)软件包没有被安装在环境的site-packages目录中,它们将在服务器的dist-packages目录中结束。 在设置venv时,我添加了--no-site-packages

我认为这是Ubuntu使用dist-packages而不是site-packages的问题,但我怎样才能让虚拟环境工作呢?

试试这个来创build你的virtualenv:

 #! /bin/bash # # Create a Python virtualenv using current code (not the distribution's outdated one) # PYTHON=/usr/bin/python2 test -x $PYTHON || PYTHON=/usr/bin/python # You can provide an alternative Python executable as the first argument, this # can for example be an interpreter installed into ~/.pythonbrew if test -x "$1"; then PYTHON="$1" shift fi # Be nice to github (get current source only once per day) venv_cached=/tmp/$USER-virtualenv-$(date +'%Y-%m-%d').py venv='https://github.com/pypa/virtualenv/raw/master/virtualenv.py' test -f $venv_cached || \ $PYTHON -c "import urllib2; open('$venv_cached','w').write(urllib2.urlopen('$venv').read())" # Call virtualenv deactivate 2>/dev/null || true $PYTHON $venv_cached "$@"