Making Python scripts run on Windows without specifying quot;.pyquot; extension(使 Python 脚本在 Windows 上运行而不指定“.py;延期)
问题描述
我希望能够在包含 python 脚本的文件夹中打开命令提示符,只需键入不带 .py 的脚本名称并观察它运行.
I want to able to open a command prompt at the folder which contains a python script and just type in the script name without the .py and watch it run.
按照谷歌上的各种提示来做这件事,我这样做了:
Following the various tips on google to do this, I do:
- 将 python.exe 添加到我的路径
- 将 .py 添加到 PATHEXT
- 尝试在浏览的窗口中打开 .py 文件.当提示:你想打开什么程序?我导航到我的 python.exe
应该发生的情况是 python.exe 应该添加到打开方式"弹出窗口中,但不是吗?我重新尝试使用 python.exe 离开我的路径.同样的问题.
What should happen is the python.exe should be added to the 'Open With' pop up, but it is not? I re try with the python.exe off my path. Same problem.
请注意,每次我在控制面板中设置路径.python的版本是2.7.为了让事情变得更奇怪,我可以将 .py 程序与 pythonw 相关联——但这没有用,因为我想要控制台.
Note every time I set a path it is in the control panel. Version of python is 2.7. And to make things stranger, I can associate .py programs with pythonw - but this is no use, as I want the console.
任何帮助表示赞赏.
推荐答案
如前所述将 .PY 添加到 PATHEXT
Add .PY to PATHEXT as noted before
然后做:
assoc .py=Python.File
ftype Python.File=c:Python27python.exe "%1" %*
在命令提示符下执行脚本或在资源管理器中双击不需要将 python 添加到路径中,仅当您想启动交互式 python 会话或使用 python yourscript.py 运行脚本时代码>
Adding python to the path isn't necessary to execute the script in a command prompt or double clicking in Explorer, only if you want to start an interactive python session or running the script with python yourscript.py
参见 http://docs.python.org/2/using/windows.html 了解更多详情.
See http://docs.python.org/2/using/windows.html for more details.
这篇关于使 Python 脚本在 Windows 上运行而不指定“.py";延期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使 Python 脚本在 Windows 上运行而不指定“.py";延期
基础教程推荐
- 对多索引数据帧的列进行排序 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
