当前位置:   article > 正文

ubuntu (16.07) 默认python版本从python3改为python2_ubuntu python3切换python2

ubuntu python3切换python2

记录一下,今天给一台x86机子装了ros系统,sudo ros init时候,报了错误:

  1. File "/usr/bin/rosdep", line 6, in <module>
  2.     from pkg_resources import load_entry_point
  3.   File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2927, in <module>
  4.     @_call_aside
  5.   File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2913, in _call_aside
  6.     f(*args, **kwargs)
  7.   File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2940, in _initialize_master_working_set
  8.     working_set = WorkingSet._build_master()
  9.   File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 635, in _build_master
  10.     ws.require(__requires__)
  11.   File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 943, in require
  12.     needed = self.resolve(parse_requirements(requirements))
  13.   File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 829, in resolve
  14.     raise DistributionNotFound(req, requirers)
  15. pkg_resources.DistributionNotFound: The 'rosdep==0.21.0' distribution was not found and is required by the application

一:问题

我们知道,ros 默认的python库应该是python,而看起来报的错误全是python3,那么而已得知python库需要切换下。

python --version 先看一下目前额python版本, 

  1. python --version
  2. Python 3.5.2

二:解决

1:查看python2的位置:

  1. which python2
  2. /usr/bin/python2

2:切换python默认版本

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 150

3:查看可选择的版本:

  1. update-alternatives --list python
  2. /usr/bin/python2

4:切换:sudo update-alternatives --config python
如果只看一个,那无所谓了,也不用config了,我的就是如此了

  1. sudo update-alternatives --config python
  2. 链接组 python (提供 /usr/bin/python)中只有一个候选项:/usr/bin/python2
  3. 无需配置。

5:查询版本,最好重新打开一个终端

  1. python --version
  2. Python 2.7.12

搞定!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/71233
推荐阅读
相关标签
  

闽ICP备14008679号