【发布时间】:2012-03-17 21:07:03
【问题描述】:
我通过sudo pip install virtualenv 安装了 virtualenv 并创建了一些环境。但现在我发现我的默认“全局”Python 路径完全消失了。
在新的终端中,我看到如下输出:
user@localhost:~$ sudo pip install django
Requirement already satisfied (use --upgrade to upgrade): django in /usr/local/lib/python2.7/dist-packages
Cleaning up...
user@localhost:~$ ls /usr/local/lib/python2.7/dist-packages/django
bin contrib db forms __init__.py middleware template test views
conf core dispatch http __init__.pyc shortcuts templatetags utils
user@localhost:~$ python
Python 2.7.2+ (default, Oct 4 2011, 20:06:09)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named django
>>>
这里发生了什么?如何修复我的全局 Python 安装,以便它可以看到已安装的包?
【问题讨论】:
-
我很好奇如果你运行
which python会发生什么,sys.path在 Python 中的样子,以及sudo python是否知道django包。 -
@zigg,好主意。这些会帮助我更快地发现问题。
标签: python django virtualenv pip