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: 

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐