查看发现linux的python3命令指向alternatives
alternatives是Linux系列操作系统的一个内置命令,即使最小化安装也有该命令,它的主要作用就是版本控制切换,比如,你的系统内有多个Python版本,Python3.8,Python2.7.5,Python3.6,。
[root@santiagod-andible openstack-ansible]# find /usr/bin/ |grep python3 |xargs -i ls -ld {} -rwxr-xr-x 1 root root 7760 Aug 26 2021 /usr/bin/python3.9 lrwxrwxrwx 1 root root 31 Aug 25 2021 /usr/bin/python3.6 -> /usr/libexec/platform-python3.6 lrwxrwxrwx 1 root root 32 Aug 25 2021 /usr/bin/python3.6m -> /usr/libexec/platform-python3.6m lrwxrwxrwx 1 root root 25 Aug 10 09:51 /usr/bin/python3 -> /etc/alternatives/python3 lrwxrwxrwx 1 root root 17 Aug 25 2021 /usr/bin/python3.6-config -> python3.6m-config lrwxrwxrwx 1 root root 39 Aug 25 2021 /usr/bin/python3.6m-config -> /usr/libexec/platform-python3.6m-config lrwxrwxrwx 1 root root 46 Aug 25 2021 /usr/bin/python3.6m-x86_64-config -> /usr/libexec/platform-python3.6m-x86_64-config lrwxrwxrwx 1 root root 32 Aug 11 12:46 /usr/bin/python3-config -> /etc/alternatives/python3-config -rwxr-xr-x 1 root root 57 Aug 26 2021 /usr/bin/python3.9-config -rwxr-xr-x 1 root root 3616 Aug 26 2021 /usr/bin/python3.9-x86_64-config
查看alternatives发现,这个链接指向又回去了
[root@santiagod-andible openstack-ansible]# find /etc/alternatives/ |grep python3|xargs -i ls -ld {} lrwxrwxrwx 1 root root 18 Aug 10 09:51 /etc/alternatives/python3 -> /usr/bin/python3.6 lrwxrwxrwx 1 root root 34 Aug 10 09:51 /etc/alternatives/python3-man -> /usr/share/man/man1/python3.6.1.gz lrwxrwxrwx 1 root root 25 Aug 11 12:46 /etc/alternatives/python3-config -> /usr/bin/python3.6-config
此时我感觉,切换默认python解释器还是通过alternatives稳妥一点,担心直接修改软链接可能会造成版本冲突
切换默认python3
[root@santiagod-andible openstack-ansible]# alternatives --config python There are 3 programs which provide 'python'. Selection Command ----------------------------------------------- *+ 1 /usr/libexec/no-python 2 /usr/bin/python3 3 /usr/bin/python3.9 Enter to keep the current selection[+], or type selection number: 3 [root@santiagod-andible openstack-ansible]# alternatives --display python python - status is manual. link currently points to /usr/bin/python3.9
标签:bin,Aug,python,alternatives,python3.6,usr,linux,root From: https://www.cnblogs.com/santia-god/p/17622763.html