因此,我尝试在Django中启动一个项目,并根据此处的文档安装了所有内容:https://docs.djangoproject.com/en/3.0/intro/tutorial01/
现在,当我尝试使用命令“ py manage.py runserver”运行服务器时,出现以下错误:
Traceback (most recent call last):
File "manage.py", line 10, in main
from django.core.management import execute_from_command_line
ImportError: No module named 'django'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 16, in main
) from exc
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?
我已经添加了所有必需的环境变量,但我无法弄清这里出了什么问题。任何帮助将是巨大的! :)
答案 0 :(得分:0)
尝试使用命令“ python manage.py runserver”运行服务器。检查是否已安装django,并使用命令“ pip Frozen”检查所有已安装的python软件包。 如果您在virtalenv中安装了djanjo,请检查virtualenv是否已激活?
答案 1 :(得分:0)
确保在您的系统上安装了django。
py -m django
如果该命令导致您遇到错误"No moduled named django"
,请尝试以下命令:
py -m pip install django
答案 2 :(得分:0)
确保您安装了虚拟环境
py -m pip install virtualenvwrapper-win
workon myvenv
python -m venv myvenv
确保您在正确的目录中以加载虚拟环境
PS C:\Users\taylo\Desktop\django-project\myweb> . myvenv\Scripts\activate.ps1
您将知道它的激活时间类似于此(myvenv) 然后像这样通过pip安装Django
(myvenv) PS C:\Users\taylo\Desktop\django-project\myweb> pip install django
创建您的项目并CD进入
(myvenv) PS C:\Users\taylo\Desktop\django-project\myweb> django-admin startproject myproject
(myvenv) PS C:\Users\taylo\Desktop\django-project\myweb> ls
(myvenv) PS C:\Users\taylo\Desktop\django-project\myweb> cd myproject
要运行本地服务器,文件夹路径应对齐
(myvenv) PS C:\Users\taylo\Desktop\django-project\myweb\myproject> python manage.py runserver