Python 安装django后无法打开manage.py
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36131744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
cannot open manage.py after installing django
提问by Mel
I have a problem in setting up django.
我在设置 django 时遇到问题。
My situation: I have Anaconda Python 2.7 in my Windows 8 computer. On the Anaconda command prompt window, I type: pip install django
. This is successful.
我的情况:我的 Windows 8 计算机中有 Anaconda Python 2.7。在 Anaconda 命令提示符窗口中,我输入:pip install django
. 这是成功的。
Then I create a folder named "newproject". On the command prompt I went to the folder "newproject". Then django-admin.py startproject newproject
. This is successful.
然后我创建一个名为“newproject”的文件夹。在命令提示符下,我转到文件夹“newproject”。然后django-admin.py startproject newproject
。这是成功的。
Then I run python manage.py runserver
. It tells me
然后我跑python manage.py runserver
。它告诉我
"...can't open file 'manage.py': [Errno 2] No such file or directory"
I checked out udemy django installation guide and other guides on the net. I have even set up a virtual environment. But the main problem is always: can't open file 'manage.py'
我在网上查看了 udemy django 安装指南和其他指南。我什至建立了一个虚拟环境。但主要问题始终是:can't open file 'manage.py'
回答by rnevius
You're not in the proper directory...In the case you described, you should have:
您不在正确的目录中...在您描述的情况下,您应该:
mkdir newproject
(not sure why you're doing this...but we'll continue with it)cd newproject
django-admin.py startproject newproject
cd newproject
← A key missing part from what you did. You need to change into the directory where manage.pyresides. Verify it by usingls
at the command prompt after switching into the directory.python manage.py runserver
mkdir newproject
(不知道你为什么要这样做......但我们会继续这样做)cd newproject
django-admin.py startproject newproject
cd newproject
← 您所做的工作中缺少的一个关键部分。您需要切换到manage.py所在的目录。ls
切换到目录后,通过在命令提示符下使用来验证它。python manage.py runserver
Use ls
often, if you need, to double check where you are in the directory tree.
ls
如果需要,请经常使用以仔细检查您在目录树中的位置。
回答by Aditya Singh Chauhan
You are not in the correct directory. You need to do cd newprojectand the execute your runservercommand.
您不在正确的目录中。您需要执行cd newproject并执行您的runserver命令。
回答by terminatorash2199
you need to change your directory to the directory of the project.
您需要将目录更改为项目目录。
- open your environment by typing
activate environment_name
- change the directory to the folder in which you want to create the
project by
cd Folder_Name
- then create your project by
django-admin startproject Project_Name
- then change the directory to your project folder
- if you also want to create an app then type
python manage.py startapp App_name
- to confirm if it works type
python manage.py runserver
, then you should get a link in the terminal. copy and paste that link in the browser and you should see a successful page.
- 通过键入打开您的环境
activate environment_name
- 将目录更改为要在其中创建项目的文件夹
cd Folder_Name
- 然后通过以下方式创建您的项目
django-admin startproject Project_Name
- 然后将目录更改为您的项目文件夹
- 如果您还想创建一个应用程序,请输入
python manage.py startapp App_name
- 确认它是否工作类型
python manage.py runserver
,那么你应该在终端中获得一个链接。将该链接复制并粘贴到浏览器中,您应该会看到一个成功的页面。
回答by Arvand
For me it was because the manage.py didn't get created and the problem was that:
对我来说,这是因为 manage.py 没有被创建,问题是:
In windows instead of typing "django-admin.py" just type "django-admin" and it will create the manage.py file
在 Windows 中,不要输入“django-admin.py”,只需输入“django-admin”,它就会创建 manage.py 文件
回答by Ahmed M.Gaballah
The reason of this problem is because you're in the first project directory "parent directory", and you have to go to your project "newproject" that has the manage.py file.
这个问题的原因是因为你在第一个项目目录“父目录”中,你必须去你的项目“newproject”有manage.py文件。
The way to this is simple:
方法很简单:
cd "name of your project", E.g. cd newproject
python manage.py runserver
cd "您的项目名称",例如 cd newproject
python manage.py runserver
回答by Giggity
You need to include a .
after you create the project.
.
创建项目后,您需要包含一个。
Eg: django-admin.py startproject newproject .
例如: django-admin.py startproject newproject .
This will allow you to run python manage.py runserver
from where you are.
这将允许您python manage.py runserver
从您所在的位置运行。
回答by Heamalatha Pradeeba
You should navigate to the inner directory where your manage.py resides. For example:
If you have created projectname as
Django-admin startproject loginapp
您应该导航到 manage.py 所在的内部目录。例如:如果您已创建项目名称为 Django-admin startproject loginapp
Step 1:Go to loginapp
Step 2:Click on it
Step 3:You will find another loginapp and manage.py folder inside that
Step 4:Use this rootpath commandprompt
Step 5:Enter py manage.py runserver
Now it will work
第 1 步:转到 loginapp
第 2 步:单击它
第 3 步:您将在该文件夹中找到另一个 loginapp 和 manage.py 文件夹
第 4 步:使用此 rootpath 命令提示符
第 5 步:输入 py manage.py runserver
现在它将起作用
回答by khalid btb
That can happen because manage.py doesn't have permissions. Check the existence of manage.py throughout newproject, If exist you can fix it with:
这可能是因为 manage.py 没有权限。在整个新项目中检查 manage.py 是否存在,如果存在,您可以使用以下方法修复它:
$cd newproject
$chmod +x manage.py
Finally, try to execute python manage.py runserver
最后,尝试执行 python manage.py runserver
回答by Andres Quiroga
I was having the same problem, when Windows 10 changed credentials, Docker lost the access to drives. The fix for this issue, I reset the credentials in docker-desktop > shared Drives > reset credentials at bottom.
我遇到了同样的问题,当 Windows 10 更改凭据时,Docker 无法访问驱动器。为了解决这个问题,我在 docker-desktop > 共享驱动器 > 底部重置凭据中重置了凭据。
回答by Abhishek
can't open file 'manage.py': [Errno 2] No such file or directory"
无法打开文件“manage.py”:[Errno 2] 没有这样的文件或目录”
here is the solution
这是解决方案
step 1: command -> django-admin startproject project_name
第 1 步:命令 -> django-admin startproject project_name
step 2: command -> cd project_name
第 2 步:命令 -> cd project_name
step 3: command -> python manage.py startapp app_name
第 3 步:命令 -> python manage.py startapp app_name
try it may fix your problem
尝试它可能会解决您的问题