(笔记)ROS学习——rosdep update 超时解决方法

 

前言
本篇文章记录在安装ROS时碰到的rosdep update超时问题,并记录了为解决这个问题我所尝试的解决方法。相关环境为Ubuntu20.04,ROS Noetic。

 

关于 rosdep
安装ros的最后一步是rosdep init和rosdep update,rosdep是解决ros包依赖问题的一个工具。
rosdep init会从ros官方服务器上下载一个“20-default.list”文件,放在“/etc/ros/rosdep/sources.list.d/”路径下。“20-default.list”里是一些yaml文件的网址,这些yaml文件里保存着一些ros工具或者常见ros包的依赖关系,即这些ros工具或者ros包依赖于哪些其它ros包。这一步网上相关教程说会出问题,但我自己试的时候很流畅,没有出问题。
当执行rosdep update,rosdep会尝试访问yaml文件内的网址,把yaml里的信息转存到本地,这样当配置上述ros工具或者ros包时,ros会按照依赖关系自动把所需的依赖一并下载。
由于rosdep update需要访问github,国内对于github的访问是经常出问题的,在这一步经常会因为网络问题而失败。失败图片如下:

所以,无论是哪种解决方案,其核心都是使得rosdep update命令能够访问到相应的文件。在解决过程中,一共尝试了三种解决方案,成功了两种。

 

解决方案一:修改DNS(失败)
由于是因为访问github失败,所以首先想到的方法是修改DNS,因为通过修改DNS可以流畅的访问github。

常规的方法是修改“/etc/hosts”文件,把“raw.githubusercontent.com”服务器的ip地址注册到里边。“raw.githubusercontent.com”的服务器ip可能会变化,可以通过 https://www.ipaddress.com 这个网站来查询当前的ip。
不过我一般用的是GitHub520和SwitchHosts来修改github的dns,非常好用。GitHub520提供了一个自动更新github相关服务器ip地址的链接,而SwitchHosts可以将该链接内的信息自动更新入host。用这个方法平常我上github基本是没问题了。
修改dns后,效果:

可以看到,这个方法让我多前进了几步,但是仍旧无法完成rosdep update。

 

解决方案二:资源代理(成功):本人使用此方法已验证
网站https://ghproxy.com/支持github的资源代理,可以用此代理加速rosdep对Github的访问,进而解决rosdep update失败问题。我们要在rosdep的若干个脚本文件中,把 https://ghproxy.com/ 添加到相应URL前。该方法参考rosdep update 超时失败2021最新解决方法。
下述要修改的文件中,由于我是Ubuntu20.04,ROS Noetic,相关文件在python3路径下,其他版本安装路径可能不一样,可以用find命令在系统中查找。如对文件1,可用命令:sudo find / -name rep3.py进行查找,查找结果如下:

关于find命令的更多用法,可以参考linux下快速查找文件

 

修改文件1:/usr/lib/python3/dist-packages/rosdep2/rep3.py

# REP3_TARGETS_URL = 'https://raw.githubusercontent.com/ros/rosdistro/master/releases/targets.yaml'
REP3_TARGETS_URL = 'https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/releases/targets.yaml'

修改文件2:/usr/lib/python3/dist-packages/rosdistro/__init__.py

# DEFAULT_INDEX_URL = 'https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'
DEFAULT_INDEX_URL = 'https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'

修改文件3:/etc/ros/rosdep/sources.list.d/20-default.list

# os-specific listings first
yaml https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx

# generic
yaml https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
yaml https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
yaml https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
gbpdistro https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml fuerte

# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead

再执行rosdep update,成功:


解决方案三:将文件下载到本地(成功)
该方法核心思想就是将难以访问的文件通过一定办法保存到本地,然后直接访问本地文件。该方法参考一定能解决ROS系统 rosdep update超时问题de简单方法。
一共有七个yaml文件需要获取,获取方法多样。

直接用git命令下载
git clone https://github.com/ros/rosdistro.git

如果git clone 速度较慢,可以直接进入https://github.com/ros/rosdistro.git,到网页下载,速度有时候会提高。
我下载了相关文件,百度网盘,可自取。
可直接将下列网页内容保存到相应名字的文件。虽然下列网页也是github服务器上的,但是打开非常流畅。但操作略繁琐。
https://raw.githubusercontent.com/ros/rosdistro/master/releases/targets.yaml
https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml

现在我们已经获取了需要的文件,只需要将对应的路径设置为刚下载来的文件就好。记录rosdistro存放地址,我存放在/home/ubuntu2004/rosdistro。根据自己存放文件路径的不同,下面修改后的值也不同。

修改文件1:/usr/lib/python3/dist-packages/rosdep2/rep3.py

# REP3_TARGETS_URL = 'https://raw.githubusercontent.com/ros/rosdistro/master/releases/targets.yaml'
REP3_TARGETS_URL = REP3_TARGETS_URL = 'file:///home/ubuntu2004/rosdistro/releases/targets.yaml'

修改文件2:/usr/lib/python3/dist-packages/rosdistro/__init__.py

# DEFAULT_INDEX_URL = 'https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'
DEFAULT_INDEX_URL = DEFAULT_INDEX_URL = 'file:///home/ubuntu2004/rosdistro/index-v4.yaml'

修改文件3:/etc/ros/rosdep/sources.list.d/20-default.list

# os-specific listings first

yaml file:///home/ubuntu2004/rosdistro/rosdep/osx-homebrew.yaml osx

# generic

yaml file:///home/ubuntu2004/rosdistro/rosdep/base.yaml
yaml file:///home/ubuntu2004/rosdistro/rosdep/python.yaml
yaml file:///home/ubuntu2004/rosdistro/rosdep/ruby.yaml
gbpdistro file:///home/ubuntu2004/rosdistro/releases/fuerte.yaml fuerte

# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead

再执行rosdep update,成功:

 

原文链接:https://blog.csdn.net/senlijiu/article/details/124203913

posted on   tdyizhen1314  阅读(527)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示