成功执行 Django python 命令的*唯一*方法是使用“python ...PATH...django-admin.py [options]”。为什么不能减少呢?

2023-11-29

这是后续这个问题.

The 第一步在 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, e.g.
                        "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, e.g.
                        "/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

Result:

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, e.g.
                        "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, e.g.
                        "/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

我重复了所有这些命令,遵循this tip:

全部注释掉django-admin.py文件,并将其添加到顶部:import sys; print(sys.version, sys.executable)

Command:

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

Command:

python django-admin.py startproject mysite

回复:

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

Command:

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

Command:

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.

按照建议here(感谢@Humdinger),这可能是路径问题。今天早些时候有was一个旧版本的Python,位于一个不明显的目录中,我将其删除。

这是我的路径

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*。唯一匹配的文件如下:

  • python34.dll in C:\Windows\System32(不明白这是什么)
  • python.exe and pythonw.exe in C:\applications\programming\python_341
  • ipython and ipython3 in C:\applications\programming\python_341\Scripts\

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

对这里发生的事情有什么想法吗?为什么不能以任何方式减少该命令而不导致错误?


我在 django 中遇到了同样的问题,并在以下位置找到了解决方案https://docs.djangoproject.com/en/1.7/howto/windows/。那里提到如果你使用 Django 1.7 那么我们必须写Django 管理代替django-admin.py从我们的命令提示符。希望有帮助。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

成功执行 Django python 命令的*唯一*方法是使用“python ...PATH...django-admin.py [options]”。为什么不能减少呢? 的相关文章

随机推荐