在我安装完ros-kinetic版本之后,需要进行初始化
sudo rosdep init
这个时候系统报了一个错误信息提示我某样东西没有安装
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'rosdep==0.21.0' distribution was not found and is required by the application
报错原因:
ubuntu 默认python版本为python3,而不是python2;
joanna@joanna-System-Product-Name:~$ python --version
Python 3.6.4
joanna@joanna-System-Product-Name:~$ update-alternatives --list python
/usr/local/bin/python3
网上的错误答案
上网搜索资料之后说是需要安装Python3 版本的 rosdep
sudo apt install python3-rosdep
为了安装这个,又需要去安装一堆依赖库
sudo apt-get install python3-catkin-pkg
sudo apt-get install python3-rospkg
sudo apt-get install python3-rosdep-modules
神奇的是,你会发现在安装这些的时候ros当中的很多组建被奇怪的卸载掉了!!
不信的话你再运行一遍
sudo apt-get install ros-kinetic-desktop
会发现还有很多东西没安装,如果又重新安装了,又会报最先前的错误,于是又去重新装 Python3 版本的 rosdep,反反复复死循环;
正确解决方案—设置python2为默认版本
- 查看python2的位置;
which python2
- 设置为可选择版本;
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 150
- 查看可选择版本;
update-alternatives --list python
joanna@joanna-System-Product-Name:~$ which python2
/usr/bin/python2
joanna@joanna-System-Product-Name:~$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 150
joanna@joanna-System-Product-Name:~$
/usr/bin/python2
/usr/local/bin/python3
- 切换Python版本;
sudo update-alternatives --config python
- 查看当前版本;
python --version
joanna@joanna-System-Product-Name:~$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/local/bin/python3 150 auto mode
1 /usr/bin/python2 150 manual mode
2 /usr/local/bin/python3 150 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/bin/python2 to provide /usr/bin/python (python) in manual mode
joanna@joanna-System-Product-Name:~$ python --version
Python 2.7.12
- 运行
sudo rosdep init
joanna@joanna-System-Product-Name:~$ sudo rosdep init
Wrote /etc/ros/rosdep/sources.list.d/20-default.list
Recommended: please run
rosdep update