我正在尝试在 CentOS 6 上将 python 配置为 3.9。
这是我的步骤:
[root@quickstart ~]# alternatives --install /usr/bin/python python /usr/local/bin/python3.9 10
[root@quickstart ~]# alternatives --config python
There is 1 program that provides 'python'.
Selection Command
-----------------------------------------------
*+ 1 /usr/local/bin/python3.9
Enter to keep the current selection[+], or type selection number: 1
[root@quickstart ~]# alternatives --display python
python - status is manual.
link currently points to /usr/local/bin/python3.9
/usr/local/bin/python3.9 - priority 10
Current `best' version is /usr/local/bin/python3.9.
[root@quickstart ~]# alternatives --set python /usr/local/bin/python3.9
但是当我发出 python --version 时,仍然是 2.6
[root@quickstart ~]# python --version
**Python 2.6.6**
[root@quickstart ~]#
编辑:即使按照这些步骤,$PATH 的第一个参数中仍然有 python 2.6。可能是吗? $PATH 配置在哪里? /etc/bashrc 或 ~/.bashrc 都没有它。
[root@quickstart ~]# whereis python
python: /usr/bin/python2.6 /usr/bin/python /usr/bin/python2.6-config /usr/lib/python2.6 /usr/lib64/python2.6 /usr/local/bin/python3.9-config /usr/local/bin/python3.9 /usr/local/lib/python3.9 /usr/include/python2.6 /usr/share/man/man1/python.1.gz
[root@quickstart ~]#
编辑2: /etc/alternatives 的 python 为 3.9,但不是全局的。
[root@quickstart alternatives]# pwd
/etc/alternatives
[root@quickstart alternatives]# ./python --version
Python 3.9.10
[root@quickstart alternatives]# python --version
Python 2.6.6
[root@quickstart alternatives]#
答案1
将 python2.6 添加到替代方案中:
sudo alternatives --install /usr/bin/python python /usr/local/bin/python2.6 5
然后将python3.9设置为默认:
sudo alternatives --config python
或者用所需的 python 版本覆盖符号链接:
sudo ln -fs /usr/bin/python3.9 /usr/bin/python