如何使python脚本可执行? [英] How do I make a python script executable?
本文介绍了如何使python脚本可执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何使用自己的命令行名称(如"myscript")运行python脚本,而不必在终端中执行"python myscript.py"?
How can I run a python script with my own command line name like 'myscript' without having to do 'python myscript.py' in the terminal?
推荐答案
-
在脚本顶部添加一个shebang行:
Add a shebang line to the top of the script:
#!/usr/bin/env python
将脚本标记为可执行文件:
Mark the script as executable:
chmod +x myscript.py
将包含它的目录添加到您的PATH
变量中. (如果要粘贴,则必须在主目录的.bashrc
或.bash_profile
中执行此操作.)
Add the dir containing it to your PATH
variable. (If you want it to stick, you'll have to do this in .bashrc
or .bash_profile
in your home dir.)
export PATH=/path/to/script:$PATH
这篇关于如何使python脚本可执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文