[英]Couldn't import Django when launching test server
When running the command: 运行命令时:
python manage.py runserver
To launch a test server, I get the following error: 要启动测试服务器,出现以下错误:
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?
Steps I took to get this error: 我采取以下步骤来获取此错误:
1) I downloaded the Django project from my Linux VPS (without the virtual environment). 1)我从Linux VPS(没有虚拟环境)下载了Django项目。 I am using Windows 10 on this current system.
我在当前系统上使用Windows 10。
2) I created a new virtual environment in that folder using: 2)我使用以下命令在该文件夹中创建了一个新的虚拟环境:
virtualenv myprojectenv
3) The env was created successfully, I now have the following folders/files: 3)env已成功创建,我现在具有以下文件夹/文件:
myproject myprojectenv static manage.py
4) I activate the env ( myprojectenv\\scripts\\activate
), success - my commandline changes to 4)我激活了env(
myprojectenv\\scripts\\activate
),成功-我的命令行更改为
(myprojectenv) C:\\ (path to my folder)
5) I install Django using 5)我使用安装Django
pip install django
Django successfully installed, when checking the version, it returns 2.1.1: Django已成功安装,在检查版本时,它返回2.1.1:
python -c "import django; print(django.get_version())
2.1.1
6) I go back to the main dir where manage.py is, I try to run the test server with 6)我回到manage.py所在的主目录,我尝试用
python manage.py runserver
And I get the error (specified above). 我得到了错误(上面指定)。 So, what have I done wrong here?
那么,我在这里做错了什么? I have the env folder correctly in that directory, Django installed.
我在该目录中已正确安装了env文件夹Django。 It still can't find it.
它仍然找不到。
I thought the problem may be with my Django files, but no. 我认为问题可能出在我的Django文件上,但没有。 When I start a new project from the myprojectenv env using
当我使用myprojectenv env启动新项目时
django-admin startproject mysite
The mysite folder gets created - I go into that folder (where manage.py is) and I try to launch the test server again. 创建了mysite文件夹-我进入该文件夹(manage.py所在的文件夹),然后尝试再次启动测试服务器。 It still can't find Django!
它仍然找不到Django! Any help is appreciated.
任何帮助表示赞赏。
--- make all of them in order ---使它们全部井然有序
virtualenv example virtualenv示例
source example/bin/activate 源示例/ bin /激活
cd example cd范例
pip install django pip安装Django
django-admin.py startproject mysite django-admin.py startproject mysite
cd mysite cd mysite
python manage.py runserver python manage.py运行服务器
--It have to work 100% -必须工作100%
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.