Django Installation Error (No Module Named Django)

匿名 (未验证) 提交于 2019-12-03 01:00:01

问题:

I am using Mac OS X Mavericks.

I have an error with installing Django. Using the "pip install" command I installed Django. It is in the directory below.

Requirement already satisfied (use --upgrade to upgrade):  Django in /usr/local/lib/python2.7/site-packages Cleaning up... 

When I type "python" into the command line, and then "import django", it says No Module Named Django.

Based on reading other answers, apparently sys.path will say which directories I can install Django in.

So I did:

import sys for x in sys.path: print x  

This gives the following list of directories:

/Library/Python/2.7/site-packages/scikit_learn-0.14.1-py2.7-macosx-10.9-intel.egg /Library/Python/2.7/site-packages/setuptools-2.0.1-py2.7.egg /Library/Python/2.7/site-packages/py2app-0.7.3-py2.7.egg /Library/Python/2.7/site-packages/modulegraph-0.10.4-py2.7.egg /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 

So clearly my pip install Django is not going in the right directory.

How can I use pip install to put Django in one of those directories?

There is a somewhat similar question here: During installation of Django, why do I keep getting ImportError: No module named django? . The answer recommends adding the directory to the path using sys.path.append('insert path here') but I'm not sure if this is a good way of solving the problem.

回答1:

Well for anyone else with this problem who is still confused how virtualenv and all that stuff works, and may have installed too many incompatible versions: The simple fix is to just download the tar.gz from the Django downloads page and follow the instructions they gave:

tar xzvf Django-1.6.1.tar.gz cd Django-1.6.1 sudo python setup.py install 


回答2:

Try --user while using pip ( which gives admin privilege)

pip install --user django



回答3:

You need to install virtual env to overcome this problem. Read about virtualenvwrapper, its a nice one.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!