如何使 python 脚本在 Windows 上可执行? [英] How to make python scripts executable on Windows?

查看:65
本文介绍了如何使 python 脚本在 Windows 上可执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
在 Windows 上设置 Python 以不输入 pythoncmd

当我在 Linux 甚至 Mac OS 上从命令行使用 python 时,我会利用 shebang 并直接运行我的一些脚本,如下所示:./myScript.py.我确实需要授予此脚本可执行权限,但仅此而已.

When I use python on Linux, or even Mac OS from command line, I take advantage of the shebang and run some of my scripts directly, like so: ./myScript.py. I do need to give this script executable permissions, but that is all.

现在,我刚刚在 Windows 7 上安装了 Python 3.1.2,我希望能够从命令行执行相同的操作.我还需要遵循哪些额外步骤?

Now, I just installed Python 3.1.2 on Windows 7, and I want to be able to do the same from command line. What additional steps do I need to follow?

推荐答案

这总结得比我说的要好:

This sums it up better than I can say it:

http://docs.python.org/faq/windows.html

更具体地说,请查看标题为如何使 Python 脚本可执行?"的第二部分

More specifically, check out the 2nd section titled "How do I make Python scripts executable?"

在 Windows 上,标准 Python 安装程序已经将 .py 扩展名与文件类型 (Python.File) 相关联,并为该文件类型提供了一个运行解释器(D:\Program Files\Python\python.exe "%1" %*).这足以使脚本从命令提示符处以 foo.py 的形式执行.如果您希望能够通过简单地输入 foo 而没有扩展名来执行脚本,您需要将 .py 添加到 PATHEXT 环境变量.

On Windows, the standard Python installer already associates the .py extension with a file type (Python.File) and gives that file type an open command that runs the interpreter (D:\Program Files\Python\python.exe "%1" %*). This is enough to make scripts executable from the command prompt as foo.py. If you’d rather be able to execute the script by simple typing foo with no extension you need to add .py to the PATHEXT environment variable.

这篇关于如何使 python 脚本在 Windows 上可执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆