python - django明明已经安装成功了,为什么还提示No module named django.core.management
怪我咯
怪我咯 2017-04-17 11:47:07
[Python讨论组]

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

ipython manage.py shell

就报错下面的结果:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/Library/Python/2.7/site-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
    202             else:
    203                 filename = fname
--> 204             __builtin__.execfile(filename, *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_line(sys.argv)

ImportError: No module named django.core.management

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

import django.db 

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

怎么破啊?????

怪我咯
怪我咯

走同样的路,发现不同的人生

全部回复(3)
ringa_lee

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

PHP中文网

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

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

python manage.py shell

改为

python2.7 manage.py shell

可以解决问题。

PHPz

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
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号