python无法打开_脚本 - Python3.8突然无法运行

问题:

我一直可以从终端python运行(运行python解释器)脚本,但今天突然无法从shell运行python脚本。

hello.py包含:#!/usr/bin/python3

print('Hello world!')

ls -la hello.py显示:-rwxrwxr-x 1 Lexible Lexible 44 May 25 08:35 hello.py% file -k hello.py

hello.py: Python script text executable12- a /usr/bin/python3 script, UTF-8 Unicode (with BOM) text executable

% cat -e hello.py

M-oM-;M-?#!/usr/bin/python3$

print('Hello world!')$

ls -la /usr/bin/python3*显示:lrwxrwxrwx 1 root root 9 Mar 13 05:20 /usr/bin/python3 -> python3.8

-rwxr-xr-x 1 root root 5457536 Apr 27 08:53 /usr/bin/python3.8

lrwxrwxrwx 1 root root 33 Apr 27 08:53 /usr/bin/python3.8-config -> x86_64-linux-gnu-python3.8-config

lrwxrwxrwx 1 root root 16 Mar 13 05:20 /usr/bin/python3-config -> python3.8-config

-rwxr-xr-x 1 root root 384 Mar 27 19:39 /usr/bin/python3-futurize

-rwxr-xr-x 1 root root 388 Mar 27 19:39 /usr/bin/python3-pasteurize% which python

/usr/bin/python

% which python3

/usr/bin/python3

甚至。% python3

Python 3.8.2 (default, Apr 27 2020, 15:53:34)

[GCC 9.3.0] on linux

Type"help","copyright","credits" or"license" for more information.

>>> print('Hello world!')

Hello world!

>>>

和% python3 hello.py

Hello world!

% python hello.py

Hello world!

但是突然(多年来,我一直在运行这个python脚本)无法运行:% ./hello.py

./hello.py: 1: #!/usr/bin/python3: not found

./hello.py: 2: Syntax error: word unexpected (expecting")")

sudo apt install -f --reinstall python3 python3.8 python3-minimal python3.8-minimal libpython3.8-minimal 全部不可用。

答案1:

你可以使用。dos2unix hello.py # Install using `sudo apt install dos2unix` (if not already installed)

dos2unix将处理所有Windows/DOS类型的字符/行尾并将其转换为类Unix。

或者,也可以使用删除BOM表。sed -i '1s/^xEFxBBxBF//' hello.py

答案2:

具体地说,EF BB BF在字节23 21之前,应该是脚本的开头。./hello.py

Hello world!

相关文章

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值