成功执行Django python命令的* only *方法是使用“python … PATH … django-admin.py ”。 为什么不能减less?

这是这个问题的后续。

在Django教程中的第一步说打电话

django-admin.py startproject mysite 

但是这是结果:

 R:\jeffy\programming\sandbox>django-admin.py startproject mysite Usage: django-admin.py subcommand [options] [args] Options: -v VERBOSITY, --verbosity=VERBOSITY Verbosity level; 0=minimal output, 1=normal output, 2=verbose output, 3=very verbose output --settings=SETTINGS The Python path to a settings module, eg "myproject.settings.main". If this isn't provided, the DJANGO_SETTINGS_MODULE environment variable will be used. --pythonpath=PYTHONPATH A directory to add to the Python path, eg "/home/djangoprojects/myproject". --traceback Raise on exception --no-color Don't colorize the command output. --version show program's version number and exit -h, --help show this help message and exit Type 'django-admin.py help <subcommand>' for help on a specific subcommand. Available subcommands: [django] check compilemessages createcachetable dbshell diffsettings dumpdata flush inspectdb loaddata makemessages makemigrations migrate runfcgi runserver shell sql sqlall sqlclear sqlcustom sqldropindexes sqlflush sqlindexes sqlinitialdata sqlmigrate sqlsequencereset squashmigrations startapp startproject syncdb test testserver validate Note that only Django core commands are listed as settings are not properly configured (error: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.). R:\jeffy\programming\sandbox> 

这与今天早些时候发生的事情截然不同(旧的Python被隐藏在一个不相关的应用程序的安装目录中 – 它已经被删除并从PATH中删除)。

这也是行不通的

 python django-admin.py startproject mysite 

结果:

 python: can't open file 'django-admin.py': [Errno 2] No such file or directory 

而这也不是:

 c:\applications\programming\python_341\Scripts\django-admin.py startproject mysite 

响应:

 R:\jeffy\programming\sandbox>c:\applications\programming\python_341\Scripts\django-admin.py startproject mysite Usage: django-admin.py subcommand [options] [args] Options: -v VERBOSITY, --verbosity=VERBOSITY Verbosity level; 0=minimal output, 1=normal output, 2=verbose output, 3=very verbose output --settings=SETTINGS The Python path to a settings module, eg "myproject.settings.main". If this isn't provided, the DJANGO_SETTINGS_MODULE environment variable will be used. --pythonpath=PYTHONPATH A directory to add to the Python path, eg "/home/djangoprojects/myproject". --traceback Raise on exception --no-color Don't colorize the command output. --version show program's version number and exit -h, --help show this help message and exit Type 'django-admin.py help <subcommand>' for help on a specific subcommand. Available subcommands: [django] check compilemessages createcachetable dbshell diffsettings dumpdata flush inspectdb loaddata makemessages makemigrations migrate runfcgi runserver shell sql sqlall sqlclear sqlcustom sqldropindexes sqlflush sqlindexes sqlinitialdata sqlmigrate sqlsequencereset squashmigrations startapp startproject syncdb test testserver validate Note that only Django core commands are listed as settings are not properly configured (error: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.). 

但是这样做

python c:\applications\programming\python_341\Scripts\django-admin.py startproject mysite

按照以下提示 ,我重复了所有这些命令:

注释掉整个django-admin.py文件,并在顶部添加: import sys; print(sys.version, sys.executable) import sys; print(sys.version, sys.executable)

命令:

 django-admin.py startproject mysite 

响应:

3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] C:\applications\programming\python_341\python.exe

命令:

 python django-admin.py startproject mysite 

响应:

 python: can't open file 'django-admin.py': [Errno 2] No such file or directory 

命令:

 c:\applications\programming\python_341\Scripts\django-admin.py startproject mysite 

响应:

3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] C:\applications\programming\python_341\python.exe

命令:

python c:\applications\programming\python_341\Scripts\django-admin.py startproject mysite

响应:

3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] C:\applications\programming\python_341\python.exe

作为一个额外的证据:

 [R:\]python Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. 

正如这里所build议的(感谢@Humdinger),这可能是一个PATH问题。 今天早些时候,在一个非显而易见的目录中有一个旧版本的Python,我删除了它。

这是我的path

 C:\applications\programming\python_341\; C:\applications\programming\python_341\Scripts; C:\applications\programming\; .; C:\Program Files\Common Files\ArcSoft\Bin; C:\Program Files\Common Files\Microsoft Shared\Windows Live; C:\Program Files\Windows Live\Shared; C:\Windows; C:\Windows\System32\Wbem; C:\Windows\System32\WindowsPowerShell\v1.0\; C:\Windows\system32; C:\applications\programming\apache-ant-1.8.1\bin; C:\applications\programming\apache-maven-3.1.1\bin; C:\applications\programming\jdk_7_51\bin; C:\applications\video\quicktime\QTSystem\; C:\Program Files\TortoiseSVN\bin; %M2%; C:\applications\utilities\gpg4win\pub 

我经历了这些目录中的每一个,并做了一个dir *python* 。 唯一匹配的文件如下:

  • C:\Windows\System32 python34.dll (不明白这是什么)
  • python.exepythonw.exeC:\applications\programming\python_341
  • ipythonipython3C:\applications\programming\python_341\Scripts\

仅供参考:Django版本1.7c2,Python版本3.1.4,Windows 7,32位。

关于这里发生了什么的任何想法? 为什么不能以任何方式减less这个命令,而不会造成错误呢?

Solutions Collecting From Web of "成功执行Django python命令的* only *方法是使用“python … PATH … django-admin.py ”。 为什么不能减less?"

我得到了与Django相同的问题,并在https://docs.djangoproject.com/en/1.7/howto/windows/获得解决方案&#x3002; 这里提到,如果你使用的是Django 1.7,那么我们必须在命令提示符下输入 django-admin而不是django-admin.py 。 希望它有帮助。

我们有非常类似的问题,但我可以解决它,而无需通过一半的疑难解答步骤。

原来,我有;C:\Python34\Scripts\路径出现在用户变量为…和系统变量。 我可能不小心添加了用户变量的路径,并忘记删除它。

删除你的用户变量中的;C:\Python34\Scripts\路径,并且它应该修复这个问题。