Python Django:没有名为 django.core.management 的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19342896/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 13:31:24  来源:igfitidea点击:

Django:No module named django.core.management

pythondjango

提问by MathCs

I am a Django newbie and want to explore the power of this famous framework.

我是 Django 新手,想探索这个著名框架的强大功能。

After all setups I ran

在所有设置之后我跑了

sudo python manage.py syncdb,

sudo python manage.py syncdb,

and I get this error

我收到这个错误

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

I use virtualenv and virtualenvwrapper, and I activated my working virtualenv by issuing a workoncommand.

我使用 virtualenv 和 virtualenvwrapper,并通过发出workon命令激活了我的工作 virtualenv 。

Also, when I ran which python, I got this:

另外,当我跑时which python,我得到了这个:

/home/myname/Envs/EnvName/bin/python,

/home/myname/Envs/EnvName/bin/python,

and pip freeze| grep - djangoreturns:

pip freeze| grep - django返回:

Django==1.5.4
django-toolbelt==0.0.1

The first line of my manage.py is #!/usr/bin/env python.

我的 manage.py 的第一行是#!/usr/bin/env python.

Also

python2.7 -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"

python2.7 -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"

gives

/home/myname/Envs/EnvName/lib/python2.7/site-packages

/home/myname/Envs/EnvName/lib/python2.7/site-packages

and in this directory, I do see a folder named django.

在这个目录中,我确实看到了一个名为 django 的文件夹。

So I guess I am really stuck, anyone please?

所以我想我真的被卡住了,有人请吗?

回答by Guilherme David da Costa

This first line its probably making it use your python from /usr/bin/env.

第一行可能使它使用来自/usr/bin/env.

You could try two things in this case:

在这种情况下,您可以尝试两件事:

1) If you didn't already, you should activate your virtualenv and then install Django:

1) 如果你还没有,你应该激活你的 virtualenv 然后安装 Django:

source /home/myname/Envs/EnvName/bin/activate
pip install django

2) Remove first line of manage.py which I don't thing would be a problem since you are using python manage.py ..., unless you didn't activatedyour virtualenv before.

2) 删除 manage.py 的第一行,因为您正在使用python manage.py ...,我认为这不会成为问题,除非您之前没有使用过activatedvirtualenv。



UPDATE:

更新:

There is really nothing more that what it's saying. Python couldn't find django, so you just need to activate(which I think you already did) and pip install django.

真的没有什么比它所说的更多了。Python 找不到 django,所以你只需要activate(我认为你已经这样做了)和pip install django.



ANOTHER UPDATE:

另一个更新:

Your problem its actually simpler to solve. You are trying sudo python manage.py syncdband when you do using sudo you are not accessing python from virtualenv, so just remove sudo and everything should run.

你的问题实际上更容易解决。您正在尝试sudo python manage.py syncdb,当您使用 sudo 时,您并没有从 访问 python virtualenv,因此只需删除 sudo,一切都应该运行。

回答by Victor.Liu

system.

系统。

Maybe you already fix it out. But I post this for later fellows.

也许你已经解决了。但我把这个贴给以后的人。

try:

尝试:

which python sudo which python

which python sudo which python

after you see the different. you are able to do:(with you env activated: source activate)

在你看到不同之后。你可以这样做:(你的环境激活:源激活)

sudo `which python` manage.py shell

sudo `which python` manage.py shell

hope helps

希望有帮助

cheers

干杯