Ubuntu/usr/bin/env: python: 没有这样的文件或目录

我更新了内核,在 Ubuntu 不能正常工作之后,PS: 我尝试执行“ meld”命令,它会报告“/usr/bin/env: python: No such file or directory”, 然后执行“ sudo apt-get install python”并得到结果“ python 已经是最新版本了。”我该怎么办。


我不擅长 linux,你能告诉我如何恢复我的 linux 到最后一个正确的状态,或重新安装 Python 正常。

240772 次浏览

我自己也被这个错误难住了,我想我应该发布一下我是如何解决这个问题的。

我的问题是一个错误:

: No such file or directory

Which made little sense to me. My problem is that my editor had silently converted the script from Unix LF to Windows CR/LF line-termination. A rather unfortunate upshot of this is that "#!/usr/bin/env python" actually became "#!/usr/bin/env python\015" where \015 is the invisible CR character... /usr/bin/env was, then, unable to find a command "python\015" - hence the file-not-found error.

Converting the script to Unix line-ending convention solved my problem... but only after a few minutes' head-scratching.

问题场景 :

/usr/bin/env: ‘python’: No such file or directory

可能的解决方案 # 1

  • 如果没有安装 Python 3,请安装它: apt-get install python3

可能的解决方案 # 2

  • 如果已经安装了 Python3,请运行以下命令: whereis python3

  • 然后我们创建一个到它的符号链接: sudo ln -s /usr/bin/python3 /usr/bin/python

编辑: 嗨,大家好,我注意到@mchid 在我的回答 sudo apt install python-is-python3下面发布了一个更好的 解决方案

On Ubuntu 20.04 and newer, there is a package to fix this problem. Run the following commands:

sudo apt update
sudo apt install python-is-python3

运行 apt-cache show python-is-python3获取更多信息。

@ mchid 的回答是你应该去争取的。

仅供参考,

如果你这样做: $ python

它会说 Command 'python' not found ...

但如果你这样做: $ python3应该能用。

所以,只要修改 Shebang 行

from !#/usr/bin/env python 到强度 !#/usr/bin/env python3,你就可以开始了。

(这是自动通过做 sudo apt install python-is-python3)

This answer for android build system error 对于 Python 3

如果收到“/usr/bin/env‘ python’no such file or directory”错误消息,请使用下列解决方案之一: 如果你的 Ubuntu 20.04.2 LTS 是一个新安装的(相对于升级的) Linux 版本:

sudo ln -s /usr/bin/python3 /usr/bin/python

f using Git version 2.19 or greater, you can specify --partial-clone when performing repo init. This makes use of Git's partial clone capability to only download Git objects when needed, instead of downloading everything. Because using partial clones means that many operations must communicate with the server, use the following if you're a developer and you're using a network with low latency:

repo init -u https://android.googlesource.com/platform/manifest -b master --partial-clone --clone-filter=blob:limit=10M

您可以在 下载源代码

May 2022: For anyone who just updated to 蒙特雷12.3 it appears the update replaces python with python3. Downloading 巨蟒 fixes the issues in Xcode and 饭桶 command line. Be sure to read the two comments below.

对于面临同样问题的 MacOS 用户和用自制软件安装 python3的用户:

sudo ln -s /opt/homebrew/bin/python3 /opt/homebrew/bin/python

Additional possible solution if the other suggestions from the mates are not working is to convert the .py scripts into UNIX format.

You can do so by installing dos2unix, before converting your scripts. You can do with something like this:

sudo apt install dos2unix

Once installed, you can convert your script accordingly:

dos2unix <filename>.py

你可在此了解更多有关 Dos2unix的资料。

--

另外,尝试在本地运行脚本,看看它是否正常工作,您还需要注意在脚本中包含 hashbang

#!/usr/bin/env python3
  • 请注意,以上是针对 python3的,如果需要,请使用 python

创建一个符号链接为我解决了问题

sudo ln -s /usr/bin/python3 /usr/bin/python