所以,为了解决这个问题,这一直都是完美的,直到今天。
今天我跑python manage.py runserver
时,它发出错误,说
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named django.core.management
经过大量挖掘后,我发现我的django安装在/usr/local/lib/python2.7/site-packages/
(pip install django
放置它的位置),但是python现在正在/Library/Python/2.7/site-packages
中找到它
如何告诉python django安装在上面的那个目录中?
仅供参考,这是我的sys.path
['', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-
scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
'/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
'/Library/Python/2.7/site-packages']
答案 0 :(得分:2)
您可以通过在终端
中执行以下操作来添加到python路径的路径sudo vi ~/.bash_profile
然后将此行添加到.bash_profile文件
export PYTHONPATH=/usr/local/lib/python2.7/site-packages/
退出终端并再次打开它。现在你应该很好
答案 1 :(得分:1)
你可以尝试这样的事情。
sudo vi ~/.bash_profile
export PYTHONSTARTUP=/usr/local/lib/python2.7/site-packages/
and modify sys.path at runtime with this
import sys
sys.path.insert(0, '/usr/local/lib/python2.7/site-packages')
that could be necessary later for your apache and .wsgi files.