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

1 投票
2 回答
4231 浏览
提问于 2025-04-18 06:54

我在命令行中用 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,也没有修改任何源代码,因为昨天一切都运行得很好。我不明白发生了什么。

2 个回答

3

你可能已经安装了Django,但你使用的Python版本中并没有Django在它的site-packages文件夹里。你需要检查一下你正在使用哪个版本的Python,以及你安装了哪个版本的Django。也许你从昨天开始更改了默认的Python解释器:

$ python
Python 2.7.3 (default, Dec 18 2012, 13:50:09)
Type "help", "copyright", "credits" or "license" for more information.
>>> from django.core.management import execute_from_command_line
>>>

[...]
$ python3
Python 3.2.3 (default, Jul 23 2012, 16:48:24)
Type "help", "copyright", "credits" or "license" for more information.
>>> from django.core.management import execute_from_command_line
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named django.core.management

在这里,我的Python 2.7的site-packages文件夹里有Django,但在Python 3里没有,所以它在我的PYTHONPATH中找不到任何django模块。

0

先把django卸载了,然后再重新安装一次。

这样可能就能解决问题了。

撰写回答