ubuntu下同时存在python3.5和python3.6,如何设置默认为python3.5

ubuntu下先是安装了python3.6和python2.7,现在由于其他需要又装了python3.5,但现在终端中输入python3 --version 命令显示默认加载python3.6,那么如何让它默认python3.5启动呢:

  1. 使用以下命令,更改python默认为python3.5:
1 sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
2 sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150
3 sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 200
  1. 取消原本的 Python 3.6 ,并将 Python3 链接到最新的python3.5 上:
1 sudo mv /usr/bin/python3 /usr/bin/python3-old
2 sudo ln -s /usr/bin/python3.5 /usr/bin/python3
  1. 成功默认从python3.5启动:
1 nuc@xy:/usr/lib/x86_64-linux-gnu$ python
2 Python 3.5.2 (default, Apr 16 2020, 17:47:17) 
3 [GCC 5.4.0 20160609] on linux
4 Type "help", "copyright", "credits" or "license" for more information.
  1. 切换回来链接文件:
1 sudo rm /usr/bin/python3
2 sudo mv /usr/bin/python3-old /usr/bin/python3
  1. 现在发现直接在终端中输入python及具体版本号,即可加载你需要的python环境:
 1 nuc@xy:/usr/lib/x86_64-linux-gnu$ python2
 2 Python 2.7.12 (default, Oct  8 2019, 14:14:10) 
 3 [GCC 5.4.0 20160609] on linux2
 4 Type "help", "copyright", "credits" or "license" for more information.
 5 >>> 
 6 nuc@xy:/usr/lib/x86_64-linux-gnu$ python3
 7 Python 3.5.2 (default, Apr 16 2020, 17:47:17) 
 8 [GCC 5.4.0 20160609] on linux
 9 Type "help", "copyright", "credits" or "license" for more information.
10 >>> 
11 nuc@xy:/usr/lib/x86_64-linux-gnu$ python3.6
12 Python 3.6.10 (default, Dec 19 2019, 23:04:32) 
13 [GCC 5.4.0 20160609] on linux
14 Type "help", "copyright", "credits" or "license" for more information.
15 >>> 
posted @ 2020-05-20 00:52  墨池有雨  阅读(645)  评论(0)    收藏  举报