/usr/bin/env: ‘python’: 没有该文件或目录

我正在尝试在Windows Ubuntu Bash上安装 Gitlab开发工具包$python3 的输出结果。
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

$python 输出

The program 'python' can be found in the following packages:
 * python-minimal
 * python3
Try: sudo apt install <selected package>

当我尝试做这个的时候:
sudo apt-get install build-essential 
./configure 
make -j4 # adjust according to your available CPU capacity 
sudo make install

这是在./configure之后的输出结果。
$ ./configure
/usr/bin/env: ‘python’: No such file or directory

$ python --version 

The program 'python' can be found in the following packages:
 * python-minimal
 * python3
Try: sudo apt install <selected package>

$which -a python

怎么解决这个问题?我对Ubuntu不太熟悉,有什么办法吗?

2请编辑您的问题并展示这些命令的输出结果:i) python --version;ii) which -a python - terdon
1这没道理。你说“它按照应该的方式启动了Python”,但是你的输出显示你没有安装Python。你真的运行了python2或其他什么吗? - terdon
我的错,我在编写Python之前使用了$ alias python=python3。然后重新打开时消失了,尽管它没有解决问题。 - mertselimb
请编辑您的问题并澄清。您是否已安装Python?如果您在命令行中运行python会发生什么?您是指只安装了python3吗? - terdon
我编辑了这个问题。 - mertselimb
9个回答

对于Ubuntu 20.04,您可以使用以下软件包来执行python命令。而且它是Python 3版本。
sudo apt install python-is-python3

套餐描述:

Description: symlinks /usr/bin/python to python3

 Starting with the Debian 11 (bullseye) and Ubuntu 20.04 LTS (focal)
 releases, all python packages use explicit python3 or python2
 interpreter and do not use unversioned /usr/bin/python at all. Some
 third-party code is now predominantly python3 based, yet may use
 /usr/bin/python.
 .
 This is a convenience package which ships a symlink to point
 the /usr/bin/python interpreter at the current default python3. It may
 improve compatibility with other modern systems, whilst breaking some
 obsolete or 3rd-party software.

1在我最新的内核更新Linux Mint 20之后遇到了这个问题。没想到有这么多的小部件使用了Python! - zzapper
2为我修复了在Ubuntu 20.04上的youtube-dl。谢谢。 - Charles Clayton

问题情境:
/usr/bin/env: ‘python’: No such file or directory

可能的解决方案#1

如果尚未安装Python 3,请安装它:apt-get install python3

可能的解决方案#2

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

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


2在Lubuntu 20.04上对我有用,并解决了我的问题。谢谢! - Munsko
解决方案2在Kali Linux上有效,谢谢。 - Alexandre Elshobokshy

我在安装 Ubuntu 18.04 并尝试运行一些 Python 脚本后遇到同样的问题。
我尝试过:
sudo apt-get install python2.7-minimal

但是我仍然遇到了相同的错误。我通过以下方法解决了它:
sudo apt install python-minimal

这是真的正确的:之后 python --version 会显示 _python 2.7.14_。 - Mohammad Kanan
1这个解决了我的问题,但被接受的答案没有...真奇怪... - Diego
对我来说也一样,执行sudo apt install python-minimal解决了问题。 - user12345
1python-minimal已经不存在了,而python2-minimal也无法正常工作。 - aderchox

你似乎已经安装了 python3,但它不叫做 python,而且你想要运行的脚本(configure)需要 python 2。因此:
1. 安装Python2 ``` sudo apt-get install python2.7-minimal ```
2. 再次运行它 ``` ./configure ```
如果再次失败,请明确使用python2调用它。
/usr/bin/python2.7 configure

另一个解决方案:

$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
update-alternatives: using /usr/bin/python3 to provide /usr/bin/python (python) in auto mode

在我的20.04LTS系统上进行了测试和验证。有关详细信息,请参阅“man update-alternatives”。并且,“不需要安装Python2才能使其正常工作。”

我有同样的问题,通过以下命令将Python链接到Python2.7,问题得到解决。
cd /usr/bin
sudo mv python python.bak
sudo ln -s /usr/bin/python2.7 /usr/bin/python

1在尝试安装youtube-dl时,也适用于python3。我不想安装另一个版本...只需简单地进行链接即可。 - Amit

如果你不想搞砸你的系统配置,你可以只需替换你的configure文件的第一行。
1. 用你喜欢的文本编辑器打开它 2. 将`#!/usr/bin/env python`替换为`#!/usr/bin/env python3` 3. 保存并继续玩耍吧!

仅供参考...我遇到了类似的问题 - 在Docker容器中运行Python脚本失败,显示"没有该文件或目录"。我的解决办法是在代码的检出和IDE中强制使用Unix风格的换行符(因为它是从Windows主机绑定挂载到容器中的)。

检查第一行的拼写。已知尾部空格可能会导致shell无法定位到shell...

"#!/usr/bin/env tclsh "

拖尾空格混淆了bash。