如何使Python脚本在Windows上可执行?

发布于 2024-10-04 02:09:31 字数 396 浏览 0 评论 0原文

可能的重复:
在 Windows 上设置 Python 以不键入 python cmd

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

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

Possible Duplicate:
Set up Python on Windows to not type python in cmd

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

走走停停 2024-10-11 02:09:31

这比我能说的更好地总结了它:

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

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

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

This sums it up better than I can say it:

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文