解决rosdep init和rosdep update根本问题

ubuntu18.04安装melodic遇到的问题

针对目前安装ROS时出现的一些指令问题进行解析,主要卡在rosdep init和rosdep update这里,主要是被墙的太严重了。

下面开始解决它

sudo rosdep init
ERROR: cannot download default sources list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
Website may be down.

 在进行rosdep init的时候需要联网访问这个网址,然而这个网址无法进入,导致一直卡这报错过不去,目前网上有很多方法,我也都尝试了,可以参考一下

https://blog.csdn.net/u013468614/article/details/102917569

https://www.guyuehome.com/12640

https://zhuanlan.zhihu.com/p/43345574
https://link.zhihu.com/?target=https%3A//www.cnblogs.com/liwe1004/p/11795932.html
https://link.zhihu.com/?target=https%3A//blog.csdn.net/maolong2725/article/details/82530722

也可以找到一个文件,加一句话主要看运气,比较玄学,方法如下:

#打开hosts文件
sudo vim /etc/hosts
#在文件末尾添加
151.101.84.133  raw.githubusercontent.com
#保存后退出再尝试
或者添加
151.101.76.133 raw.githubusercontent.com

解决思路

在进行rosdep init 的时候访问raw.githubusercontent.com,这个其实就是github的用户数据服务器。rosdep 程序下载的就是github.com/ros/rosdistro这个包里的yaml文件。
因此得到一个思路就是:首先下载github.com/ros/rosdistro包,将下列文件里面的默认的进入raw.githubusercontent.com去下载文件的url地址全部改为本地的下载的包的地址。
解决过程

第一步

首先进入www.github.com/ros/rosdistro去把这个包下载下来

包名rosdistro-master应改为rosdistro

也可以从我的网盘下载

链接:https://pan.baidu.com/s/1B4E_spuSJ_E1MANxWVrLfw
提取码:ja5d

第二步

修改这个包中rosdep/source.list.d/下的文件20-default.list,将这个文件中指向raw.githubusercontent.com的url地址全部修改为指向本地文件的地址(自己放置该包的地址),也就是该下载好的包的地址:以下是我修改好的样例:

# os-specific listings first
yaml file:///home/xxx/rosdistro/rosdep/osx-homebrew.yaml osx

# generic
yaml file:///home/xxx/rosdistro/rosdep/base.yaml
yaml file:///home/xxx/rosdistro/rosdep/python.yaml
yaml file:///home/xxx/rosdistro/rosdep/ruby.yaml
gbpdistro file:///home/xxx/rosdistro/releases/fuerte.yaml fuerte

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

***注意:***在py语言中:url本地文件地址格式是:file://+文件地址,后面更改其他文件中地址的时候也一样。

第三步

修改/usr/lib/python2.7/dist-packages/rosdep2/main.py中的默认的url的地址,但是经过代码阅读,该文件中并不存在指向raw.githubusercontent.com的代码。而且经过对代码的分析,提示报错的代码就在该文件中

def command_init(options):
    try:
        data = download_default_sources_list()
    except URLError as e:
        print('ERROR: cannot download default sources list from:\n%s\nWebsite may be down.' % (DEFAULT_SOURCES_LIST_URL))
        return 4
    except DownloadFailure as e:
        print('ERROR: cannot download default sources list from:\n%s\nWebsite may be down.' % (DEFAULT_SOURCES_LIST_URL))

由于其调用了download_default_sources_list()这个函数
而该函数就在/usr/lib/python2.7/dist-packages/rosdep2该文件夹下面的sources_list.py文件里面。而这个文件里面的代码则进行了访问raw.githubusercontent.com的操作,因此修改该默认url即可

# default file to download with 'init' command in order to bootstrap
# rosdep
DEFAULT_SOURCES_LIST_URL = 'file:///home/xxx/rosdistro/rosdep/sources.list.d/20-default.list'

# seconds to wait before aborting download of rosdep data

总结:该步实际并不是修改 main.py 文件里面默认url的指向地址,而是修改同文件夹下的sources_list.py文件里面的代码

第四步

修改以下两个文件里面的代码,修改方法类似:

/usr/lib/python2.7/dist-packages/rosdep2/rep3.py
/usr/lib/python2.7/dist-packages/rosdistro/__init__.py

下面是我分别修改后的样例:

修改rep3.py文件

/usr/lib/python2.7/dist-packages/rosdep2/rep3.py文件:
# location of targets file for processing gbpdistro files
REP3_TARGETS_URL = 'file:///home/xxx/rosdistro/releases/targets.yaml'

# seconds to wait before aborting download of gbpdistro data

修改__init__.py的文件

/usr/lib/python2.7/dist-packages/rosdistro/__init__.py的文件:

  

# index information

DEFAULT_INDEX_URL = 'file:///home/xxx/rosdistro/index-v4.yaml'

def get_index_url():

然后进行sudo rosdep init  就没有什么问题了

如果你是ubuntu20.04安装noetic的话,就要更改一些细节了:noetic不是更改/usr/lib/python2.7/dist-packages/了,而是更改/usr/lib/python3/dist-packages/

最后感谢原博主:

https://blog.csdn.net/nanianwochengshui/article/details/105702188

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章