python安装在ubuntu中但找不到python命令

Bon*_*oni 18 python lubuntu 18.04

我已经在我的 ubuntu 18.04 中安装了 python 2.7 和 python 3.7 但是当我

键入 python 它显示

  Command 'python' not found, but can be installed with:

  sudo apt install python3       
  sudo apt install python        
  sudo apt install python-minimal

  You also have python3 installed, you can run 'python3' instead.
Run Code Online (Sandbox Code Playgroud)

但我已经安装了python。

Gry*_*ryu 21

正如评论中所建议的,您可以按如下方式创建别名:

alias python='python3'
Run Code Online (Sandbox Code Playgroud)

通过将其添加到该~/.bashrc文件末尾的文件中,使用下一个命令退出并在当前终端中重新加载它:. ~/.bashrc

或使用链接:

正如你在下面看到的,我python指向python2python2指向python2.7

要实现相同的目的,请使用 sudo ln -s /usr/bin/python2.7 /usr/bin/python2 && sudo ln -s /usr/bin/python2 /usr/bin/python

如果你想python指向第三个版本,你可以使用相同的,但最后一个命令应该是:sudo ln -s /usr/bin/python3 /usr/bin/python

例子

$ whereis python
python: /usr/bin/python3.7 /usr/bin/python2.7-config /usr/bin/python2.7 /usr/bin/python3.7m-config /usr/bin/python3.7-config /usr/bin/python /usr/bin/python3.7m /usr/lib/python3.7 /usr/lib/python2.7 /usr/lib/python3.8 /etc/python3.7 /etc/python2.7 /etc/python /usr/local/lib/python3.7 /usr/local/lib/python2.7 /usr/include/python3.7 /usr/include/python2.7 /usr/include/python3.7m /usr/share/python /usr/share/man/man1/python.1.gz
user@lenovo:~$ ls -ailh /usr/bin/python*
1446954 lrwxrwxrwx 1 root root    7 ??? 10 14:32 /usr/bin/python -> python2
1446952 lrwxrwxrwx 1 root root    9 ??? 10 14:32 /usr/bin/python2 -> python2.7
1465834 -rwxr-xr-x 1 root root 3,6M ???  7 12:07 /usr/bin/python2.7
1447155 lrwxrwxrwx 1 root root   33 ???  7 12:07 /usr/bin/python2.7-config -> x86_64-linux-gnu-python2.7-config
1447156 lrwxrwxrwx 1 root root   16 ??? 10 14:32 /usr/bin/python2-config -> python2.7-config
1442842 lrwxrwxrwx 1 root root    9 ??? 12 00:23 /usr/bin/python3 -> python3.7
1449245 -rwxr-xr-x 2 root root 4,9M ??? 20 11:21 /usr/bin/python3.7
1447339 lrwxrwxrwx 1 root root   33 ??? 20 11:21 /usr/bin/python3.7-config -> x86_64-linux-gnu-python3.7-config
1449245 -rwxr-xr-x 2 root root 4,9M ??? 20 11:21 /usr/bin/python3.7m
1447340 lrwxrwxrwx 1 root root   34 ??? 20 11:21 /usr/bin/python3.7m-config -> x86_64-linux-gnu-python3.7m-config
1447341 lrwxrwxrwx 1 root root   16 ???  2 15:31 /usr/bin/python3-config -> python3.7-config
1442843 -rwxr-xr-x 1 root root  384 ??? 30  2019 /usr/bin/python3-futurize
1442847 lrwxrwxrwx 1 root root   10 ??? 12 00:23 /usr/bin/python3m -> python3.7m
1447342 lrwxrwxrwx 1 root root   17 ???  2 15:31 /usr/bin/python3m-config -> python3.7m-config
1442844 -rwxr-xr-x 1 root root  388 ??? 30  2019 /usr/bin/python3-pasteurize
1447157 lrwxrwxrwx 1 root root   14 ??? 10 14:32 /usr/bin/python-config -> python2-config
1455649 lrwxrwxrwx 1 root root   58 ??? 10  2019 /usr/bin/pythontex -> ../share/texlive/texmf-dist/scripts/pythontex/pythontex.py
1450999 -rwxr-xr-x 1 root root  306 ??? 10  2019 /usr/bin/pythontex3
Run Code Online (Sandbox Code Playgroud)

  • 在操作系统的脚下直接更改`/usr/bin/` 不是一个好主意。这样做可能会导致未来升级出现问题。更好的方法是安装 `python-is-python3`(仅在 20.04 或更新版本上),使用每个用户的 `alias python=python3`,或者直接运行 `python3`。 (2认同)

Fab*_*lao 8

此解决方案仅适用于 Ubuntu 20.04(但有时人们会查看“类似问题”以获得解决方案)

我在 Ubuntu 20.04 上遇到了同样的错误,如果你喜欢“python”来指代“python3”,你可以简单地安装python-is-python3

sudo apt-get install python-is-python3
Run Code Online (Sandbox Code Playgroud)

在此之后,调用 python 将工作得很好

  • 这是 20.04 的好建议,但 OP 询问了 18.04,其中`python-is-python3` 不存在并且操作系统的其余部分没有为`/usr/bin/python` 作为 Python 3 做好准备,并且可能如果这是被迫的,则会出乎意料地失败。 (2认同)
  • 像你所做的那样仔细地限定它似乎是合理的。谢谢。 (2认同)