如何解决ROS安装过程中rosdep init和rosdep update报错误的问题

几年没手工安装ros了,一般拉个安装好了cuda和ros等工具软件的docker image直接使用,以前安装过程中很顺利不会有什么报错,最近按照melodic/Installation/Ubuntu - ROS Wiki这里的步骤安装melodic

sudo apt install lsb-core
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt install curl
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add -
sudo apt update
sudo apt install ros-melodic-desktop-full
echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
sudo rosdep init
rosdep update

noetic/Installation/Ubuntu - ROS Wiki

sudo apt install lsb-core
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt install curl
curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add -
sudo apt update
sudo apt install ros-noetic-desktop-full
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
sudo apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential
sudo rosdep init
rosdep update

这里的步骤安装noetic,执行到curl -s https://raw.githubusercontent.com/ros/rosdistro/master/ros.asc | apt-key add -时

死掉,rosdep init和rosdep update时总是下面的报错:

ERROR: cannot download default sources list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml]:
    <urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml]:
    <urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml)

...

根本原因是执行这些步骤时需要连到raw.githubusercontent.com这个已经被墙掉的网站下载一些文件,网上推荐的解决办法一般是去修改/etc/resolve.conf或者/etc/hosts增加谷歌的服务器ip地址或githubusercontent.com的ip地址,点击这个网址raw.githubusercontent.com获取githubusercontent.com的ip地址:

 把这些地址加入到/etc/hosts里发现,每个地址访问一次后就被阻住,要过好一阵才能再访问,所以安装不能顺利进行下去。

被逼着去翻看了一下ros源码和网上信息,其实解决比较简单,对于ros.asc(我下载后上传到了这里)下载不了,可以从国内镜像网站上下载这个文件到本地,然后执行:

sudo apt-key add ros.asc

对于rosdep init和rosdep update报错思路就是把从githubusercontent.com上下载文件改成从国内的镜像网站下载即可,

执行下面的命令即完成了rosdep init 和rosdep update:

sudo apt-get install wget
sudo mkdir -p /etc/ros/rosdep/sources.list.d
wget https://mirrors.tuna.tsinghua.edu.cn/github-raw/ros/rosdistro/master/rosdep/sources.list.d/20-default.list -O /etc/ros/rosdep/sources.list.d/20-default.list
export ROSDISTRO_INDEX_URL=https://mirrors.tuna.tsinghua.edu.cn/rosdistro/index-v4.yaml && rosdep update

后来看到网上有人单独做了个工具rosdepc来替代rosdep,可以执行下面的命令安装:


sudo apt-get install python3-pip 
sudo pip install rosdepc

然后执行rosdepc init和rosdepc update

但是因为OS环境支持的字符集的不同,执行过程中可能会报下面的错误:

Traceback (most recent call last):
  File "/usr/local/bin/rosdepc", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/dist-packages/rosdepc/rosdepc.py", line 52, in main
    print(hints['welcome'])
UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-7: ordinal not in range(128)

Traceback (most recent call last):
  File "/usr/local/bin/rosdepc", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.6/dist-packages/rosdepc/rosdepc.py", line 52, in main
    print(hints['welcome'])
UnicodeEncodeError: 'ascii' codec can't encode character '\u201c' in position 145: ordinal not in range(128)

原因是这个rosdepc工具的/usr/local/lib/python3.6/dist-packages/rosdepc/rosdepc.py这个文件里写了大量的用于提示的中文字符以及@等ascii码字符集不支持的字符,把里面的包含的中文和特殊格式符都删掉即可,这些信息其实没啥用,删干净了再执行rosdepc init即可,可以看到rosdepc.py这个文件里的核心语句其实就是我上面写的那几句命令,所以完全不用安装这个工具包,直接执行这两句命令更简捷:

wget https://mirrors.tuna.tsinghua.edu.cn/github-raw/ros/rosdistro/master/rosdep/sources.list.d/20-default.list -O /etc/ros/rosdep/sources.list.d/20-default.list
export ROSDISTRO_INDEX_URL=https://mirrors.tuna.tsinghua.edu.cn/rosdistro/index-v4.yaml && rosdep update

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Arnold-FY-Chen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值