Python django-admin.py startproject 不工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3681216/
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
django-admin.py startproject is not working
提问by erikvold
after installing django I tried django-admin.py startproject mysiteand that worked, then I got a simple site working and I wanted to start on something real, so I tried django-admin.py startproject newsiteand nothing happened. Whenever I try the command nothing happens now.. any idea what is wrong?
安装 django 后,我尝试django-admin.py startproject mysite并成功了,然后我得到了一个简单的网站,我想开始做一些真实的事情,所以我尝试了django-admin.py startproject newsite,但什么也没发生。每当我尝试命令时,现在什么都没有发生……知道出了什么问题吗?
采纳答案by user699464
For anyone stumbling across this now, this problem is a result of Windows not obeying the #!C:\Path\To\Virtualenv\Scripts\Python.exe hashbang at the top of django-admin.py, and therefore running it with the wrong python.exe (evidently a virtualenv bug).
对于现在遇到这个问题的任何人来说,这个问题是由于 Windows 不遵守 django-admin.py 顶部的 #!C:\Path\To\Virtualenv\Scripts\Python.exe hashbang,因此使用错误的python.exe(显然是virtualenv 错误)。
However, with virtualenv active, you can use the following command, which will result in the correct python being used, and everything being ok:
但是,当 virtualenv 处于活动状态时,您可以使用以下命令,这将导致使用正确的 python,并且一切正常:
python C:\Path\To\Virtualenv\Scripts\django-admin.py startproject <project_name>
回答by ars
Do you have a DJANGO_SETTINGS_MODULEenvironment variable set (presumably from the mysiteproject)? If so, django thinks you're working on the old project and doesn't give you the startprojectoption. Try unsetting the environment variable and trying again.
您是否DJANGO_SETTINGS_MODULE设置了环境变量(大概来自mysite项目)?如果是这样,django 会认为您正在处理旧项目并且不给您startproject选择。尝试取消设置环境变量并重试。
回答by Monty
Go on to c:/python**/Scripts/ you must find django-admin.pythere that fixes your problem use the absolute path.
继续到 c:/python**/Scripts/ 你必须在django-admin.py那里找到使用绝对路径解决你的问题的地方。
回答by Ivan Juarez
If you are running Windows for a quick fix you can create a batch file with the following values:
如果您正在运行 Windows 以进行快速修复,您可以创建一个具有以下值的批处理文件:
@echo off
@echo "Enter Proyect name"
set /p proj_name=
set building="Building django project %proj_name%"
@echo %building%
python c:/Python27/Scripts/django-admin.py startproject %proj_name%
pause
I named the file "django.bat" and to use it you can just simply add a copy in the directory you want to start the project, execute the file and it will ask you for a project name, provide one and then Voila!!
我将文件命名为“django.bat”,要使用它,您只需在要启动项目的目录中添加一个副本,执行该文件,它会询问您一个项目名称,然后提供一个,然后瞧!
Hope this helps.
希望这可以帮助。
回答by anand24
Select a '.py' file and right click and select 'open with'
选择“.py”文件并右键单击并选择“打开方式”
Here select 'Python Launcher for Windows'
这里选择“Python Launcher for Windows”
It will solve the problem
它会解决问题
This is for Windows OS
这适用于 Windows 操作系统
回答by DustySack
I'm on a Mac and had a similar problem after installing with pip3. I reinstalled and it corrected the error. You can try going to the #django irc channel at irc.freenodes
我在 Mac 上使用 pip3 安装后遇到了类似的问题。我重新安装并纠正了错误。您可以尝试转到 irc.freenodes 上的 #django irc 频道
回答by Aminah Nuraini
Try this instead! It also works inside virtualenv
试试这个吧!它也可以在里面工作virtualenv
python "C:\Python27\Scripts\django-admin.py" startproject test2
回答by Shishir
Try out this way.
试试这个方法。
1> Look where your python is installed if cannot find it in C:/ Python().
1> 如果在 C:/Python() 中找不到,请查看 Python 的安装位置。
$ python
Python 2.6.6 (r266:84297, Aug 24 2010, 18:13:38) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.executable
'c:\Python26\python.exe'
>>> sys.exec_prefix
'c:\Python26'
>>>
>>> print '\n'.join(sys.path)
c:\Python26\lib\site-packages\setuptools-0.6c11-py2.6.egg
c:\Python26\lib\site-packages\nose-1.0.0-py2.6.egg
C:\Windows\system32\python26.zip
c:\Python26\DLLs
c:\Python26\lib
c:\Python26\lib\plat-win
c:\Python26\lib\lib-tk
c:\Python26
c:\Python26\lib\site-packages
c:\Python26\lib\site-packages\win32
c:\Python26\lib\site-packages\win32\lib
c:\Python26\lib\site-packages\Pythonwin
c:\Python26\lib\site-packages\wx-2.8-msw-unicode
2> After that move into Scripts folder. There you may find django-admin.py. Now copy full path of that file.
2> 之后进入 Scripts 文件夹。在那里你可以找到 django-admin.py。现在复制该文件的完整路径。
3>Now run this command
3>现在运行这个命令
python path of the filestartproject name of Project
项目的startproject文件名python路径
eg. python C:\Users\UserName\AppData\Local\Programs\Python\Python35-32\Scripts\django-admin.py startproject mysite
例如。python C:\Users\UserName\AppData\Local\Programs\Python\Python35-32\Scripts\django-admin.py startproject mysite
hope this will work.
希望这会奏效。
回答by Zeppie84
If everything is installed properly, when you open the command prompt, navigate to the desktop folder with
如果一切都安装正确,当你打开命令提示符时,导航到桌面文件夹
cd C:\Users\YOURNAME\Desktop
then type
然后输入
django-admin startproject YOURPROJECTNAME
The project should appear on your desktop.
该项目应该出现在您的桌面上。
If you didn't navigate to your desktop folder and run the command there, your project could be placed in the windows\system32folder on the C drive.
如果您没有导航到您的桌面文件夹并在那里运行命令,您的项目可能会被放置在windows\system32C 驱动器上的文件夹中。
回答by itsavy
For me worked without .py extension, since there was exe by that name in my windows
对我来说,没有 .py 扩展名,因为我的 Windows 中有那个名字的 exe
C:\Python27\Scripts\django-admin startproject HelloWorld
C:\Python27\Scripts\django-admin startproject HelloWorld

