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

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

  1. 使用以下命令,更改python默认为python3.5:
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 200
  1. 取消原本的 Python 3.6 ,并将 Python3 链接到最新的python3.5 上:
sudo mv /usr/bin/python3 /usr/bin/python3-old
sudo ln -s /usr/bin/python3.5 /usr/bin/python3
  1. 成功默认从python3.5启动:
nuc@xy:/usr/lib/x86_64-linux-gnu$ python
Python 3.5.2 (default, Apr 16 2020, 17:47:17) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.

  1. 切换回来链接文件:
sudo rm /usr/bin/python3
sudo mv /usr/bin/python3-old /usr/bin/python3
  1. 现在发现直接在终端中输入python及具体版本号,即可加载你需要的python环境:
nuc@xy:/usr/lib/x86_64-linux-gnu$ python2
Python 2.7.12 (default, Oct  8 2019, 14:14:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
nuc@xy:/usr/lib/x86_64-linux-gnu$ python3
Python 3.5.2 (default, Apr 16 2020, 17:47:17) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
nuc@xy:/usr/lib/x86_64-linux-gnu$ python3.6
Python 3.6.10 (default, Dec 19 2019, 23:04:32) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

猜你喜欢

转载自blog.csdn.net/qq_42091428/article/details/106226393
今日推荐