怎么在linux里运行一个py文件?

怎么在linux里运行一个py文件?,第1张

#!/usr/bin/env python\x0d\x0a#注意上面这一行必须是第一行顶头写。\x0d\x0a# python file example. \x0d\x0a# assume we name this file as "hello.py"\x0d\x0a# use shell command "chmod +x hello.py" to make this file executable. \x0d\x0a# then you are able to run it by typing "./hello.py"\x0d\x0aprint "Hello this is from python!"

有两种方式:\x0d\x0a1、直接使用pythonxxxx.py执行。其中python可以写成python的绝对路径。使用whichpython进行查询。\x0d\x0a2、在文件的头部(第一行)写上#!/usr/bin/python2.7,这个地方使用python的绝对路径,就是上面用whichpython查询来的结果。然后在外面就可以使用./xxx.py执行了。\x0d\x0a\x0d\x0a因为在linux中,python啊shell这些程序都是普通的文本格式,都需要一种程序去解释执行它。要么调用的时候指定,要么在文件头指定。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/7409713.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-05
下一篇2023-04-05

发表评论

登录后才能评论

评论列表(0条)

    保存