【发布时间】:2020-06-10 19:23:40
【问题描述】:
当我使用“manage.py runserver”命令启动我的 dajngo 应用程序时,我收到错误消息:
`Traceback (most recent call last):
File "manage.py", line 8, in
from django.core.management import execute_from_command_line
ModuleNotFoundError: No module named 'django'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 10, in
raise ImportError(
ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?`
但是,我刚刚验证了所有要求的安装,并且我的虚拟环境已很好地激活。所以我不知道为什么它不起作用。
感谢您的所有回答!
【问题讨论】:
-
您可能需要运行
python manage.py runserver。否则,您能否提供来自pip freeze的输出 -
如果你只运行python,然后'import python'会发生什么?
-
你在使用 virtualenv 吗?如果是这样,它是否“激活”?在这两种情况下,请确保已安装 django,您可以尝试
pip install django或者如果您有requirements.txt文件,pip install -r requirements.txt -
你激活venv后,可以输入python --version
-
@mattyx17 我试着只输入
python manage.py runserver,但想法相同,这里是pip freeze的提供:apturl==0.5.2 blinker==1.4 Brlapi==0.7.0 certifi==2019.3.9 chardet==3.0.4 command-not-found==0.3 cryptography==2.8 cupshelpers==1.0 dbus-python==1.2.16 defer==1.0.6 defusedxml==0.5.0 distro==1.4.0 distro-info===0.23ubuntu1 Django==2.2 django-debug-toolbar==1.11