python2.x / python3.xでPythonのデフォルトバージョンを設定する方法

1.現在のデフォルトのPythonバージョンを表示する
[root@docker ~]# python
Python 3.6.8 (default, Apr 19 2020, 23:57:12) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
2.Pythonのインストールパスを表示します。
[root@docker ~]# whereis python
python: /usr/bin/python /usr/bin/python2.7 /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /usr/local/python3/bin/python3.6m /usr/local/python3/bin/python3.6 /usr/local/python3/bin/python3.6m-config /usr/local/python3/bin/python3.6-config /usr/share/man/man1/python.1.gz
3.Pythonとソフト接続のすべてのバージョンを表示する
[root@docker ~]# ls /usr/bin/python* -l
lrwxrwxrwx. 1 root root   30 Apr 20 00:00 /usr/bin/python -> /usr/local/python3/bin/python3
lrwxrwxrwx. 1 root root    9 Apr 12 06:50 /usr/bin/python2 -> python2.7
-rwxr-xr-x. 1 root root 7216 Aug  6  2019 /usr/bin/python2.7
lrwxrwxrwx. 1 root root    7 Apr 12 06:50 /usr/bin/python_bak -> python2
4.ソフト接続を削除(バックアップ)します
[root@docker ~]# mv /usr/bin/python /usr/bin/python.bak
5.ソフト接続を再作成します
[root@docker ~]# ln -s /usr/bin/python2.7 /usr/bin/python
6.バージョンをもう一度確認します
root@docker ~]# python
Python 2.7.5 (default, Aug  7 2019, 00:51:29) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

おすすめ

転載: blog.csdn.net/Lin_Hv/article/details/106336683