【发布时间】:2019-09-03 07:27:01
【问题描述】:
我已经安装了 virtualenv,然后在我的 Windows 10 中安装了 django。激活 virtualenv 并运行:python manage.py runserver 后,我得到:
File "manage.py", line 10, in main
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:
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?
在运行django-admin.exe时也发现了:
Note that only Django core commands are listed as settings are not properly
configured (error: Requested setting INSTALLED_APPS, but settings are not
configured. You must either define the environment variable
DJANGO_SETTINGS_MODULE or call settings.configure() before accessing
settings.).
管理.py:
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'wordcount.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise 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?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
【问题讨论】:
-
你是否在你的 virtualenv 中安装了
django? -
我已经在 python 的 Scripts 文件夹下的同一路径中为 virtualenv 和 django 完成了 pip3 安装...
-
在虚拟环境中的终端上运行
pip3 freeze或pip freeze。它将列出已安装的包。检查 django 是否在该列表中。 -
是的 django 2.2 在那里
-
我建议将
manage.py中的代码添加到您的问题中。这将增加获得帮助的机会,并减少您的故事被标记和关闭的机会。
标签: django python-3.x windows virtualenv