解決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

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