我遇到安装Django的问题。似乎Python一旦安装就无法识别它。以下是我采取的步骤。我正在使用Mac OS 10.7.5 Python 2.7和Django 1.5.1
我没有使用virtualenv
我做错了什么? Python有什么理由不认识它吗?我该如何解决这个问题?
这就是我所做的:
卸载它,(带点子)
Successfully uninstalled Django
选中已卸载(通过蛋黄)
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
安装它,(带点子)
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
哪个python
/opt/local/bin/python
我没有使用virtualenv
答案 0 :(得分:4)
尝试使用pip作为超级用户:
sudo pip install -U django
为我工作......
答案 1 :(得分:4)
您的pip安装可能指向与opt/local/bin/python
上安装的python版本不同的python。您pip
可能正在与系统安装的python通信,而不是您安装的版本。
你可以考虑卸载python并在正确的路径中重新安装,或者创建一个指向你想要的python版本的virtualenv。然后任何后续安装将指向正确版本的python而不影响其他python安装