运行python脚本和#!/ usr / bin / python行 [英] Run a python script and the #!/usr/bin/python line

查看:103
本文介绍了运行python脚本和#!/ usr / bin / python行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来自MSW开发世界和linux / ubuntu中的一些东西,用于完成任务。让我难过。


如果我的python应用程序位于" / usr / local / pyscripts"命名为myapp.py,我如何设置东西,以便我可以通过命令行myapp arg1 arg2 arg3从命令行的任何地方运行它。 ? (如果需要,我可以编写bash脚本并设置别名。)

Python脚本中的shebang行是什么(好的)?操作系统的哪一部分使用它?


TIA: - )

I''m coming from the MSW development world and a few things in linux/ubuntu for "getting things done" have got me stumped.

If I have my python app in "/usr/local/pyscripts" named "myapp.py", how can I set up things so that I can run it from anywhere on the command line by simply giving the command "myapp arg1 arg2 arg3" ? (I can write bash scripts and set aliases if necessary.)

What (good) is the shebang line for in Python scripts ? What part of the OS uses it ?

TIA :-)

推荐答案

/ usr / local / pyscripts必须在您可以在.bashrc文件中设置的路径。

将执行python脚本的shebang thells。所以你可以使用python 3使用python,使用python 2.7使用另一个python。在Arch Linux上很常见,也可能是其他人。
/usr/local/pyscripts must be in your path which you can set in your .bashrc file.
The shebang thells which python your script will be executed with. So you could have python using python 3 and another one using python 2.7. Very common on Arch Linux, probably others too.


事实证明,只有在开发过程中运行时,shebang才有用。考虑到它的2个要求,简单地使用命令行就更直接了:
As it turns out, the shebang is somewhat useful only when running during development. Considering its 2 requirements it is far more direct to simply use the command line like :


python myapp.py


shebang line对于尝试运行myapp.py只是无用的:
python myapp.py

The shebang line is useless for trying to run myapp.py giving only :


这篇关于运行python脚本和#!/ usr / bin / python行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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