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