ubuntu 下切换python版本. ubuntu下如何切换程序版本

ubuntu下ros和conda安装后都会改变python的默认环境,且需要用到的python版本各不相同,安装好后我们可能需要对系统的默认python指定进行微调。

1.首先用ls /usr/bin/python 查找出来系统python2 和 python3的版本

samsu@samsu-pc:~/anaconda3/bin$ ls /usr/bin/python*
/usr/bin/python /usr/bin/python3.6-config
/usr/bin/python2 /usr/bin/python3.6m
/usr/bin/python2.7 /usr/bin/python3.6m-config
/usr/bin/python2.7-config /usr/bin/python3-config
/usr/bin/python2-config /usr/bin/python3m
/usr/bin/python2-qr /usr/bin/python3m-config
/usr/bin/python3 /usr/bin/python-config
/usr/bin/python3.6

2.这里笔者的系统版本分别为2.7和3.6。然后输入下面两个指令把2.7版本和3.6版本的python分别加入列表中

update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2
注意:如果你在上一步中查明的python版本和读者不一样,那请把命令中python版本改成自己对应版本。

3. 使用下面命令列出已经配置版本

update-alternatives --list python

samsu@samsu-pc:~$ update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.6
4.然后就可以用下面的指令来切换系统默认的python版本了

update-alternatives --config python

samsu@samsu-pc:~$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).

Selection Path Priority Status
------------------------------------------------------------
0 /usr/bin/python3.6 2 auto mode
* 1 /usr/bin/python2.7 1 manual mode
2 /usr/bin/python3.6 2 manual mode

Press <enter> to keep the current choice[*], or type selection number:

————————————————
版权声明:本文为CSDN博主「samsu0108」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/samsu0108/article/details/121220366

posted @ 2022-05-25 15:47  zxiaocheng  阅读(492)  评论(0编辑  收藏  举报