简体   繁体   English

django-admin.py startproject mysite 在 Windows 7 上运行不正常

[英]django-admin.py startproject mysite not working well on windows 7

I'm learning django and I did successfully start a site on Windows XP by following the tutorial.我正在学习 django,并且按照教程在 Windows XP 上成功启动了一个站点。

However, on Windows 7 when I issued:但是,在 Windows 7 上,当我发出:

django-admin.py startproject mysite

python.exe was started and a window appeared to ask me to choose either python.exe or other program to open a file.... python.exe 已启动,出现一个窗口,要求我选择 python.exe 或其他程序来打开文件....

Did I do anything wrong or there are more tricks for windows 7?我做错了什么还是 Windows 7 有更多技巧?

这已经被报告给了 django,请参阅http://bugs.python.org/issue7936这是一个解决方案:打开 regedit 并找到 python.exe 这样的 "C:\\Python26\\python.exe" "%1" 更改它到“C:\\Python26\\python.exe”“%1”%*

This is what worked for me: I already had c:\\python27 and c:\\python27\\Scripts in PATH.这对我有用:我已经在 PATH 中有 c:\\python27 和 c:\\python27\\Scripts。

  1. Copy django-admin.py and django-admin-script.py from c:\\python27\\Scripts to your desired folder将 django-admin.py 和 django-admin-script.py 从 c:\\python27\\Scripts 复制到你想要的文件夹
  2. with cmd go to that folder and run > django-admin startproject mysite使用 cmd 转到该文件夹​​并运行 > django-admin startproject mysite

Note that if I doesn't type python windows just opens the django-admin.py in editor.请注意,如果我不输入python windows 只是在编辑器中打开django-admin.py

I had the same error when I ran django-admin.py on the command prompt.当我在命令提示符下运行django-admin.py时,我遇到了同样的错误。 I couldn't create a projects.我无法创建项目。

I tried to run Regedit by using Find to Search python.exe and then adding %% but it was not sufficient.我尝试通过使用 Find to Search python.exe 然后添加%%来运行Regedit ,但这还不够。
I then added the necessary Path to the System PATH as shown below.然后我将必要的路径添加到系统路径,如下所示。

Open:打开:
Control Panel -> System -> Advanced -> Environment Variables -> PATH .控制面板->系统->高级->环境变量-> PATH

Add to the PATH:添加到路径:

C:\Python27\python.exe;C:\Python27\Scripts;C:\Python27\Lib\site-packages\django\bin

It Work!这行得通! Now I can Create Django Projects and applications Using Command on Windows 7.现在我可以在 Windows 7 上使用命令创建 Django 项目和应用程序。

在最新的 django(1.11.7 for now) 中,简单的django-admin可以工作,而不是django-admin.py

I had the same problem i followed django-admin.py startproject mysite not working well on windows 7 and found that the python files still associated with my text editor.我遇到了同样的问题,我按照django-admin.py startproject mysite 在 Windows 7 上运行不佳,发现 python 文件仍然与我的文本编辑器相关联。 Changing the necessary registry keys fix the issue.更改必要的注册表项可解决此问题。

I also had the same problem but don't worry its simple to solve this problem, just add "C:\\Users\\Nik's\\myenv\\Scripts" to the enviroment veriables and its done.我也有同样的问题,但不要担心解决这个问题很简单,只需将“C:\\Users\\Nik's\\myenv\\Scripts”添加到环境验证中即可。 The address may be differnt in your pc as it depends where you install it.您的电脑中的地址可能会有所不同,因为这取决于您安装它的位置。

Change the first line of django-admin.py #!/usr/bin/env python to for example #!D:\\Program Files\\Python\\python.exe (Where you install your python.exe ,that's my directory);将 django-admin.py #!/usr/bin/env python的第一行更改为例如#!D:\\Program Files\\Python\\python.exe (安装python.exe ,这是我的目录); it works.有用。

The solution is simple in Windows: Windows 中的解决方案很简单:

1-Go to C: \\ Python34 \\ Scripts 1-转到 C:\\Python34\\Scripts

2-Right click on django-admin.py 2-右键单击 django-admin.py

3-Select open with 3-选择打开方式

4-Select default program 4-选择默认程序

5-Select Laucher Python for Windows (Console) 5-Select Laucher Python for Windows(控制台)

6- Run the command in CMD Windows python django-admin.py startproject mysite 6- 在 CMD Windows 中运行命令python django-admin.py startproject mysite

In Windows 8.1, I faced the same problem.在 Windows 8.1 中,我遇到了同样的问题。 In my case when I tried to create my project, it would open the contents of the page in Internet Explorer window rather than creating the project folder.就我而言,当我尝试创建我的项目时,它会在 Internet Explorer 窗口中打开页面的内容,而不是创建项目文件夹。 I became curious of what exactly was this django-manage.py.我开始好奇这个 django-manage.py 到底是什么。 After searching, I got to django-admin.py file in the path C:\\Python34\\Scripts and I right clicked on it chose to open with default program of Launcher Python for Windows(Console).搜索后,我找到了路径 C:\\Python34\\Scripts 中的 django-admin.py 文件,我右键单击它选择使用 Launcher Python for Windows(控制台)的默认程序打开。

Again I got back to the CMD and in my project directory I entered: django-admin.py startproject mysite我再次回到 CMD 并在我的项目目录中输入:django-admin.py startproject mysite

And worked just fine.!!!并且工作得很好。!!!

I have faced the same issue and when I ran the Python installer again and clicked on the repair option, it magically fixed everything for me.我遇到了同样的问题,当我再次运行 Python 安装程序并单击修复选项时,它神奇地为我修复了所有内容。 Now, I can run django-admin straight from CMD.现在,我可以直接从 CMD 运行django-admin

  1. first of all make sure that python/Scripts is in your path首先确保 python/Scripts 在你的路径中
  2. run "django-admin startproject mysite" instead of "django-admin.py startproject mysite"运行“django-admin startproject mysite”而不是“django-admin.py startproject mysite”

I get the same problem for Windows 10. Here is how I resolve it:我在 Windows 10 上遇到了同样的问题。这是我的解决方法:

  1. I run the terminal CMD with administrator right .我以管理员权限运行终端CMD How to do that ?怎么做 ? Right click on the terminal and click on Run as administrator .右键单击终端,然后单击以管理员身份运行
  2. I install django by doing: python -m pip install django .我通过执行以下操作来安装djangopython -m pip install django You can check that django is really installed by doing: python -m pip freeze .您可以通过执行以下操作来检查django是否真的安装: python -m pip freeze If you see django in the list, then django is installed.如果您在列表中看到 django,则django已安装。
  3. Finally, I create my django project by doing: django-admin startproject project-name .最后,我通过执行以下操作来创建我的django项目: django-admin startproject project-name

NB: For step 3, you don't need the terminal with administrator right.注意:对于第 3 步,您不需要具有管理员权限的终端。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM