gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 18:15:35 25 4
gpt4 key购买 nike

这是 this question 的后续内容.

first step在 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

结果:

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 之后,我重复了所有这些命令:

Comment out the entire django-admin.py file, and add this at the top: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.

按照建议here (感谢@Humdinger),这可能是路径问题。今天早些时候,在一个不明显的目录中有一个旧版本的 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.dllC:\Windows\System32 (不明白这是什么)
  • python.exepythonw.exeC:\applications\programming\python_341
  • ipythonipython3C:\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-admin 而不是 django-admin.py 。希望有帮助。

关于python - 成功执行 Django python 命令的*唯一*方法是使用 "python ...PATH...django-admin.py [options]"。为什么不能减少呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25069236/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com