在命令提示符中运行python脚本时出现问题(特别是带有命令行参数)? [英] Issues running python scripts in Command Prompt (Specifically with command line arguments)?
问题描述
我试图在命令提示符下运行python脚本,而不先调用python.exe。我专门针对运行django-admin.py来执行此操作。我的PATH中有C:\Python26和C:\Python26\脚本。但是,如果我尝试通过以下方式运行django-admin.py:
I am trying to run my python scripts in the command-prompt without calling python.exe first. I am specifically doing this in relation to running django-admin.py. I have C:\Python26 and C:\Python26\Scripts in my PATH. However, if I try running django-admin.py by doing:
django-admin.py startproject helloworld
django-admin.py startproject helloworld
我收到消息:输入 django-admin.py help以供使用。
I get the message: Type 'django-admin.py help' for usage.
现在,经过一番试验之后,我意识到问题是由于某些原因,这些脚本的辅助参数没有被传递,因为我使用了我拥有的其他一些python脚本进行了尝试。我知道我可以通过执行以下操作来避免此问题:
Now, after some experimentation, I realized the problem is that the secondary arguments to these scripts are not being passed for some reason, since I tried it with a some other python scripts I have. I know I could avoid this problem by simply doing:
python C:\Python26\Scripts\django-admin.py startproject helloworld
python C:\Python26\Scripts\django-admin.py startproject helloworld
但是我知道应该只运行第一个命令并使其起作用,因为我之前已经使它起作用了。我到处都看过了,而且没有很多地方对您有帮助,因此,目前任何想法都对我有用。
But I know it should be possible to run the first command only and get it to work, because I had it working before. I've looked everywhere, and not many places have been helpful so any idea would be useful for me at this point.
更新:.py文件关联设置正确,并且问题仍然存在。
Update: The .py file associations were set correctly, and the problem is still occuring.
推荐答案
检查 assoc
和 ftype
。如果设置正确,则可以运行带有参数的 .py
。
Check assoc
and ftype
. If properly set, you can run a .py
with arguments.
> assoc .py
.py=Python.File
> ftype Python.File
Python.File="C:\Python26\python.exe" "%1" %*
根据安装Python的方式,这些位置可能适当,也可能不适当。您可以使用 assoc
和 ftype
设置。
Depending on how your Python was installed, these may or may not be in place. You can set them with assoc
and ftype
.
> assoc .py=Python.File
> ftype Python.File="C:\Python26\python.exe" "%1" %*
此外,如果中包含
环境变量,您可以运行 .py
PATHEXT .py
文件,而无需尾随 .py
。
Also, if .py
is included in the PATHEXT
environment variable, you can run .py
files without the trailing .py
.
> set PATHEXT=%PATHEXT%;.py
> django-admin startproject helloworld
这篇关于在命令提示符中运行python脚本时出现问题(特别是带有命令行参数)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!