#!/usr/bin/env: No such file or directory
程序员文章站
2022-03-08 20:36:40
...
一、原因:在把windows下的一个python脚本挪到linux下的时候,文件格式保存错误,应该存为unix格式。详细解释
二、解决方法:vim xx.py输入:
:set fileformat=unix
然后赋予其权限:
chmod a+x xx.py
最后执行:
./xx.py
三、linux下执行.py文件两种方式:
1.直接python执行:
python3 xx.py
2.脚本执行:
注意:这种方式程序文件首行要加上#! /usr/bin/env python3
其作用是"指定由哪个解释器来执行脚本",很多人在系统中同时安装了 Python2 和 Python3, 但是 2 和 3 是不兼容的, 所以执行脚本时必须指定解释器.
./xx.py
四、举例子:
aa.py
#!/usr/bin/env python3
from threading import Thread
from time import sleep
import random
import os
class MyThreadSing(Thread):
def run(self):
for i in range(3):
print('Sing...%d...%d'%(i,os.getpid()))
sleep(random.random())
class MyThreadDancer(Thread):
def run(self):
for i in range(3):
print('Dancer...%d...%d'%(i,os.getpid()))
sleep(random.random())
if __name__=='__main__':
sing=MyThreadSing(name='T-Sing')
print(sing.name)
print(sing.daemon)
sing.start()
dancer = MyThreadDancer(name='T-Dancer',daemon=True)
print(dancer.name)
print(dancer.daemon)
dancer.start()
#sleep(0.1)
print('game over...')
方式一:
[[email protected] demo01]# python3 aa.py
T-Sing
False
Sing...0...18295
T-Dancer
True
Dancer...0...18295
game over...
Sing...1...18295
Dancer...1...18295
Sing...2...18295
Dancer...2...18295
方式二:
[[email protected] demo01]# chmod a+x aa.py
[[email protected] demo01]# ./aa.py
T-Sing
False
Sing...0...18310
T-Dancer
True
Dancer...0...18310
game over...
Sing...1...18310
Dancer...1...18310
Sing...2...18310
推荐阅读
-
使用yum命令报错File "/usr/bin/yum", line 30 except KeyboardInterrupt, e:
-
bash: /usr/bin/autocrorder: /usr/bin/python^M: bad interpreter: No such file or directory
-
python升级带来的yum异常(解决错误File "/usr/bin/yum", line 30 except KeyboardInterrupt, e:)
-
/usr/bin/python与/usr/bin/env python的区别
-
Python 头部 #!/usr/bin/python 和 #!/usr/bin/env 的区别介绍
-
安装composer时,提示 /usr/bin/env: php: 没有那个文件或目录
-
【openWRT】编译问题/usr/bin/env: node: No such file or directory
-
Homebrew 安装 node 后,npm报 env: node no such file or directory
-
idea env: node: No such file or directory
-
【/usr/bin/env: node: No such file or directory】 的解决办法