virtualenv用于创建独立的Python环境,多个Python相互独立,互不影响,它能够在没有权限的情况下安装新套件,不同应用可以使用不同的套件版本,套件升级不影响其他应用。
Virtaulenvwrapper则是virtualenv的扩展包,用于更方便管理虚拟环境,如,新增,删除,复制,切换等。
最近在利用Virtaulenvwrapper的mkvirtualenv创建Python虚拟环境的时候,发现在创建的虚拟环境中升级django为1.8的时候,出现无法升级的状况:(机器外部已经安装django-1.6.10)
shenweiyan@localhost :: ~ => workon test (test)shenweiyan@localhost :: ~ => pip install --upgrade django==1.8 You are using pip version , however version is available. You should consider upgrading via the 'pip install --upgrade pip' command. Collecting django==1.8 Using cached Django-1.8-py2.py3-none-any.whl Installing collected packages: django Found existing installation: Django Not uninstalling Django at /usr/local/python2./lib/python2./site-packages, outside environment /App/pyweb/test Successfully installed django-
提示无法在/usr/local/python2.7/lib/python2.7/site-packages安装django-1.8。其原因就在于在全局环境变量中已经指定了PYTHONPATH,所以在安装django的时候会把1.8的版本默认安装到指定的PYTHONPATH下,从而导致django-1.8无法成功安装。
root@localhost :: ~ => cat /etc/profile ...... export PATH=/usr/local/python2./bin:$PATH export PYTHONPATH=/usr/local/python2./lib/python2./site-packages:/usr/lib/python2./site-packages:$PYTHONPATH
所以,把/etc/profile全局变量中的PYTHONPATH注释掉,再重新登录虚拟环境进行安装升级就ok了。
shenweiyan@localhost :: ~ => workon test (test)shenweiyan@localhost :: ~ (test)shenweiyan@localhost :: ~ => pip You are using pip version , however version is available. You should consider upgrading via the 'pip install --upgrade pip' command. Collecting django== Using cached Django--py2.py3-none-any.whl Installing collected packages: django Found existing installation: Django Uninstalling Django-: Successfully uninstalled Django- Successfully installed django-
ok,问题解决!!!