解决Ubuntu16.04——ROS安装报错无法初始化sudo rosdep init或roscore运行报错

一万年没写博客了,之前为了在Ubuntu环境下跑深度学习的项目就重装了系统,现在重新开始弄无人机项目之后发现之前轻而易举装了一万次的ROS竟然遇到问题了!!!

pkg_resources.DistributionNotFound: The 'rosdep==0.19.0' distribution was not found and is required by the application

废话少说,上问题!

在我安装完ros-kinetic版本之后,需要进行初始化

sudo rosdep init

这个时候系统报了一个错误信息提示我某样东西没有安装

pkg_resources.DistributionNotFound: The 'rosdep==0.19.0' distribution was not found and is required by the application

网上的错误答案

上网搜索资料之后说是需要安装Python3.5 版本的 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-full

会发现还有很多东西没安装,如果又重新安装了,又会报最先前的错误,于是又去重新装 Python3.5 版本的 rosdep,反反复复死循环。。。。。。。

正确解决方案

问题出现的真实原因其实是Ros-kinetic使用的是python2版本的rosdep,而电脑系统python版本是python3造成的。我们将系统python版本换到python2就可以了。

查看当前系统Python版本

python --version 

查看发现默认的版本的确被修改为python3.5了,但其实Ubuntu系统本身就自带有python2的版本

update-alternatives --list python

通过指令查看一下系统都要哪些版本的Python   通常都会有Python2.7的 

/usr/bin/python2.7
/usr/bin/python3.5

如果在list python那一步报错,则表示 Python 的替代版本尚未被update-alternatives 命令识别,具体解决方案请自行Google/Baidu,比较简单我就不再赘述了。

下一步就是切换Python版本的命令,通过这个命令可以在不同版本的Python之间快速切换

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   150       auto mode
* 1            /usr/bin/python2   100       manual mode
  2            /usr/bin/python3   150       manual mode

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

我们需要将Python版本切换为Python2,因此输入数字1,然后Enter就大功告成了。

初始化ROS

后面的步骤在网上各大教程里都有详细说明,我就不再说明了。

sudo rosdep init

rosdep update

echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc

source ~/.bashrc

sudo apt-get install python-rosinstall python-rosinstall-generator python-wstool build-essential

roscore

有可能会碰到一个问题,在进行初始化的时候提示

ERROR: default sources list file already exists:
	/etc/ros/rosdep/sources.list.d/20-default.list

这表示你之前其实是初始化过ROS了,不管是通过错误还是正确的方法,都初始化过了,因此本应该创建的文件已经存在,这时只要删掉该文件再重新进行初始化就好了。

sudo rm /etc/ros/rosdep/sources.list.d/20-default.list

大功告成!

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值