我是靠谱客的博主 阳光灰狼,这篇文章主要介绍#!/usr/bin/env: No such file or directory,现在分享给大家,希望可以做个参考。

一、原因:在把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...')

方式一:

[root@localhost 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

方式二:

[root@localhost demo01]# chmod a+x aa.py 
[root@localhost 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

最后

以上就是阳光灰狼最近收集整理的关于#!/usr/bin/env: No such file or directory的全部内容,更多相关#!/usr/bin/env:内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(113)

评论列表共有 0 条评论

立即
投稿
返回
顶部