(优发娱乐平台) django明明已经安装成功了,为什么还提示No module named django.core.management

django 我感觉应该是安装成功了的,已经生成了目录结构,并且导入MySQLdb也没有问题,但是我在执行

ipython manage.py shell

就报错下面的结果:

---------------------------------------------------------------------------
ImportError Traceback most recent call last
/Library/Python/2.7/site-packages/IPython/utils/py3compat.pyc in execfilefname, *where 202 else: 203 filename = fname
--> 204 __builtin__.execfilefilename, *where /Users/daodao/Desktop/djangoproject/manage.py in <module> 6 os.environ.setdefault"DJANGO_SETTINGS_MODULE", "djangoproject.settings" 7 ----> 8 from django.core.management import execute_from_command_line 9 10 execute_from_command_linesys.argv ImportError: No module named django.core.management

另外,我在Python开发环境下尝试:

import django.db 

Mac上直接弹窗『”Python”意外退出』——>好/重新打开

怎么破啊?????

多版本最好使用virtualenv,比如arch默认是python3.3,如果常用python2.7那就用2.7装一个virtualenv,以后创建项目的时候顺便创建一个虚拟环境,还干净,易于导出requirements.txt.

好吧。这个问题我还是来自答吧。

主要是Python版本的问题,在Mac系统上因为系统自带了好几个版本的Python,所以会出现诸如此类的问题,具体原因不是很清楚,先记录下来。在stackoverflow上找到的答案。

python manage.py shell

改为

python2.7 manage.py shell

可以解决问题。

Most likely you have more than one version of Django installed; note the path /usr/local/bin/django-admin.py in the error message. You may also not have your PATH environment variable set up correctly so that the MacPorts paths appear before /usr/local/bin where you may have a link to a python.org python and /usr/bin where the Apple-supplied python is. Your PATH should like something like this:

$ echo $PATH
/opt/local/Library/Frameworks/Python.framework/Versions/Current/bin:/opt/local/bin:/usr/local/bin:/usr/bin:/bin # and so forth

If not, you should modify the appropriate shell startup script, probably .bash_profile, to modify PATH permanently.

You can test whether it works by explicitly invoking the script with the MacPorts python:

$ /opt/local/bin/python2.6 /opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/bin/django-admin.py

发表评论

电子邮件地址不会被公开。 必填项已用*标注