使用 update-alternatives 时,python3 的二进制版本不正确

使用 update-alternatives 时,python3 的二进制版本不正确

我已经使用 Ubuntu 多年了,但现在我完全搞不清楚到底发生了什么。

所有这些都表明我应该使用,python3.9但实际上却如此python3.10。请帮我调试一下。

问题是我希望用指定路径update-alternatives替换pythonbin。在下面的例子中,我希望python链接到python3.9,但它没有替换它,我最终得到了 Ubuntu22.04 默认值,即python3.10

下面的日志显示python链接到/usr/bin/python哪个链接到/usr/bin/python3.9哪个实际上是python3.9。但是,当我检查时python --version它实际上是3.10

retyn@meland:~/projects/cracker$ python --version
Python 3.10.4
kretyn@meland:~/projects/cracker$ sudo update-alternatives --config python
There are 3 choices for the alternative python (providing /usr/bin/python).

  Selection    Path                 Priority   Status
------------------------------------------------------------
  0            /usr/bin/python3.9    3         auto mode
  1            /usr/bin/python3.10   1         manual mode
  2            /usr/bin/python3.8    2         manual mode
* 3            /usr/bin/python3.9    3         manual mode

Press <enter> to keep the current choice[*], or type selection number: 3
kretyn@meland:~/projects/cracker$ python --version
Python 3.10.4
kretyn@meland:~/projects/cracker$ python3 --version
Python 3.10.4
kretyn@meland:~/projects/cracker$ which python
/usr/bin/python
kretyn@meland:~/projects/cracker$ ll /usr/bin/python
lrwxrwxrwx 24 root 24 Sep 11:20 /usr/bin/python -> /etc/alternatives/python*
kretyn@meland:~/projects/cracker$ ll /etc/alternatives/python 
lrwxrwxrwx 18 root 24 Sep 11:20 /etc/alternatives/python -> /usr/bin/python3.9*
kretyn@meland:~/projects/cracker$ /usr/bin/python3.9 --version
Python 3.9.14
kretyn@meland:~/projects/cracker$ /usr/bin/python --version
Python 3.9.14
kretyn@meland:~/projects/cracker$ python --version
Python 3.10.4
kretyn@meland:~/projects/cracker$ python
Python 3.10.4 (main, Jun 29 2022, 12:14:53) [GCC 11.2.0] on linux

检查typetype -a

kretyn@meland:~$ type python
python is aliased to `python3'
kretyn@meland:~$ type -a python
python is aliased to `python3'
python is /usr/bin/python
python is /bin/python
kretyn@meland:~$ /bin/python --version
Python 3.9.14
kretyn@meland:~$ /usr/bin/python --version
Python 3.9.14
kretyn@meland:~$ python3 --version
Python 3.10.4

^ 最后一个可能是原因。有一个别名python=python3,所以python被替换,但python3没有,这就是为什么pythonpython3.10

相关内容