【发布时间】:2013-08-02 14:03:44
【问题描述】:
我在安装 Django 时遇到问题。似乎Python一旦安装就无法识别它。以下是我已采取的步骤。我正在使用 Mac OS 10.7.5 Python 2.7 和 Django 1.5.1
我没有使用 virtualenv
我做错了什么? Python 不能识别它有什么原因吗?我该如何解决这个问题?
这是我所做的:
卸载它,(使用 pip)
Successfully uninstalled Django
检查是否已卸载(通过 yolk)
localhost:mysite brendan$ yolk -l
Flask-SQLAlchemy - 0.16 - active
Flask - 0.10.1 - active
Jinja2 - 2.7 - active
MarkupSafe - 0.18 - active
Python - 2.7 - active development (/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload)
SQLAlchemy - 0.8.2 - active
Werkzeug - 0.9.1 - active
boto - 2.9.7 - active
itsdangerous - 0.22 - active
nose - 1.3.0 - active
pip - 1.3.1 - active
setuptools - 0.8 - active
tweepy - 1.7.1 - non-active
tweepy - 1.9 - active
virtualenv - 1.9.1 - active
wsgiref - 0.1.2 - active development (/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7)
yolk - 0.4.3 - active
安装它,(使用 pip)
localhost:mysite brendan$ pip install django
Downloading/unpacking django
Downloading Django-1.5.1.tar.gz (8.0MB): 8.0MB downloaded
Running setup.py egg_info for package django
warning: no previously-included files matching '__pycache__' found under directory '*'
warning: no previously-included files matching '*.py[co]' found under directory '*'
Installing collected packages: django
Running setup.py install for django
changing mode of build/scripts-2.7/django-admin.py from 644 to 755
warning: no previously-included files matching '__pycache__' found under directory '*'
warning: no previously-included files matching '*.py[co]' found under directory '*'
changing mode of /Library/Frameworks/Python.framework/Versions/2.7/bin/django-admin.py to 755
Successfully installed django
Cleaning up...
localhost:mysite brendan$ python
Python 2.7.5 (default, May 19 2013, 13:26:47)
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
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
>>>
编辑/更新:
哪个点
/Library/Frameworks/Python.framework/Versions/2.7/bin/pip
哪个蟒蛇
/opt/local/bin/python
我没有使用 virtualenv
【问题讨论】:
-
which pip和which python的结果是什么? -
您在使用虚拟环境吗?
-
你是否在系统python之外安装了另一个python?那不是系统python路径。有可能您的 pip 正在使用您的系统 python 并且 Django 安装在上面
-
@sedavidw 有可能,我不完全理解 Pythonpaths。所以我安装在 /opt/local/Library 的 Python 2.7 应该在 /Library ????
-
@Deepend,这不一定是它应该在的位置,您只需要知道安装到哪个 python pip 即可。这实际上就是 virtualenv 如此有用的原因。当你创建一个 virtualenv 时,你可以指定它使用哪个 python,然后当你安装任何库时,你知道它们将转到那个 python 而不会影响任何其他 python 安装。如果可能的话,我会启动一个virutalenv,它指向您的
/opt/local/bin/python安装并向其中添加库。这是一个很好的参考hackercodex.com/guide/…
标签: python django python-2.7