使 Python 脚本全局可执行 [英] Make Python script globally executable

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

问题描述

假设我有一个名为 say_hello.py 的单行 Python 模块.

Let's say I've got this one-line Python module called say_hello.py.

print 'Hello World'

如何使脚本从终端中的任何位置可执行?也就是说,将 Hello World 打印在我系统上任何地方的 Python 解释器之外.我在 OS X Mavericks 上运行.

How can I make the script executable from any location in my terminal? That is, having Hello World printed outside the Python interpreter anywhere on my system. I'm running on OS X Mavericks.

推荐答案

General *nix answer

脚本的第一行应该类似于:

General *nix answer

First line of script should look something like:

#!/usr/bin/python

尽管您系统上的确切路径可能有所不同.然后,使脚本可执行并将其放在 PATH 中的某个位置.

although the exact path may be different on your system. Then, make the script executable and put it somewhere in your PATH.

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

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