【机器人研习社-ROS专辑】ROSDEP UPDATE&ROSDEP INIT 问题的各种解决方法
最近新安装ROS,卡在rosdep update和rosdep init 上很久,以前的方法各种失效,各种尝试后终于解决了,在这里分享给大家。
操作系统:Ubuntu16.04/Ubuntu18.04/Ubuntu20.04
ROS版本:kinetic/melodic/noetic
- rosdep init问题
首先打开一个终端
sudo mkdir -p /etc/ros/rosdep/sources.list.d
cd /etc/ros/rosdep/sources.list.d
sudo gedit 20-default.list
将以下内容复制进20-default.list文件中
# os-specific listings first
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx
# generic
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
gbpdistro 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
# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
执行以下指令 rosdep update
(一般会失败,请继续看下文
- rosdep update 问题
方案1:https://ghproxy.com /代理模式
方案2:本地模式-将rosdistro clone到本地
最近在国内上github越来越难,国内https://raw.githubusercontent.com的可用IP越来越少,通过修改hosts文件解决rosdep update超时问题的方法已经没法再用。
操作系统:
->Ubuntu16.04/Ubuntu18.04/Ubuntu20.04
-> ROS版本:kinetic/melodic/noetic
Error
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml]:
Failed to download target platform data for gbpdistro:
The read operation timed out
Query rosdistro index https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
updated cache in /home/ricky/.ros/rosdep/sources.cache
ERROR: Not all sources were able to be updated.
方案1:
网站https://ghproxy.com/支持github的资源代理,非常好用,我们将用此代理加速rosdep对Github Raw的访问,进而解决rosdep update超时问题。
如果是ROS Noetic路径为python3,
cd /usr/lib/python3/dist-packages/rosdep2/
如果是老版本在python2.7
cd /usr/lib/python2.7/dist-packages/rosdep2/
(1)首先定位rosdep资源下载函数。从报错信息中得知,该函数名为download_rosdep_data,位于/usr/lib/python23/dist-packages/rosdep2/sources_list.py(本文以Python3 为例)。
sudo gedit /usr/lib/python3/dist-packages/rosdep2/sources_list.py
我们修改这一函数,添加:
url="https://ghproxy.com/"+url
如下
————————————————
def download_rosdep_data(url):
"""
:raises: :exc:`DownloadFailure` If data cannot be
retrieved (e.g. 404, bad YAML format, server down).
"""
try:
# http/https URLs need custom requests to specify the user-agent, since some repositories reject
# requests from the default user-agent.
url="https://ghproxy.com/"+url
if url.startswith("http://") or url.startswith("https://"):
url_request = request.Request(url, headers={'User-Agent': 'rosdep/{version}'.format(version=__version__)})
else:
url_request = url
f = urlopen(url_request, timeout=DOWNLOAD_TIMEOUT)
text = f.read()
f.close()
data = yaml.safe_load(text)
if type(data) != dict:
raise DownloadFailure('rosdep data from [%s] is not a YAML dictionary' % (url))
return data
except (URLError, httplib.HTTPException) as e:
raise DownloadFailure(str(e) + ' (%s)' % url)
except yaml.YAMLError as e:
raise DownloadFailure(str(e))
(2)在/usr/lib/python3/dist-packages/rosdep2/gbpdistro_support.py 第204行添加如下代码
gbpdistro_url = "https://ghproxy.com/" + gbpdistro_url
(3)用同样的方法修改/usr/lib/python3/dist-packages/rosdistro/__init__.py里面的DEFAULT_INDEX_URL。
sudo gedit /usr/lib/python3/dist-packages/rosdistro/__init__.py
即将DEFAULT_INDEX_URL 进行如下替换:
DEFAULT_INDEX_URL = 'https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml'
除此处外,下述文件中也含有github地址,分别是
/usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py 36行
/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py 72行
/usr/lib/python2.7/dist-packages/rosdep2/rep3.py 39行
/usr/lib/python2.7/dist-packages/rosdistro/manifest_provider/github.py 68行,118行
均可通过在地址前添加
https://ghproxy.com/
前缀来应用代理服务。
再次尝试执行rosdep update,大功告成!
rosdep update
reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml
Query rosdistro index https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Skip end-of-life distro "crystal"
Add distro "dashing"
Skip end-of-life distro "eloquent"
Add distro "foxy"
Add distro "galactic"
Skip end-of-life distro "groovy"
Skip end-of-life distro "hydro"
Skip end-of-life distro "indigo"
Skip end-of-life distro "jade"
Skip end-of-life distro "kinetic"
Skip end-of-life distro "lunar"
Add distro "melodic"
Add distro "noetic"
Add distro "rolling"
updated cache in /home/ricky/.ros/rosdep/sources.cache
方案2:
raw.githubusercontent.com实际上就是github的用户数据服务器,rosdep程序下载的就是github.com/ros/rosdistro这个repo里的yaml文件。
虽然raw.githubusercontent.com服务器无法访问,但是yaml文件可以直接从git clone的repo中获得。
思路:
将ros/rosdistro整个git下来,然后再将
•20-default.list
•/usr/lib/python2.7/dist-packages/rosdep2/gbpdistro_support.py
•/usr/lib/python2.7/dist-packages/rosdep2/rep3.py
•/usr/lib/python2.7/dist-packages/rosdistro/init.py
中的默认url全部指向本地的git,即可解决这个问题。
具体步骤
第一步:
将rosdistro clone到本地
git clone https://github.com/ros/rosdistro.git
PS-以下的所有yourname 都改成你们自己的用户名
默认会在home/yourname/下出现一个rosdistro文件夹(yourname是你的用户名)
终端打开刚刚下载(clone)下来的rosdistro文件夹
第二步:
文件1
打开文件将里面的http://raw.githubusercontent.com改成文件路径的形式
cd /home/yourname/rosdistro/rosdep/sources.list.d/
sudo gedit 20-default.list
如下:
注意如果你手动把URL改为file路径,需要删除默认URL路径中的/master/,而不是简单的把https://raw.githubusercontent.com/ros 替换为 file:///home/yourname
#os-specific listings first
yaml file:///home/yourname/rosdistro/rosdep/osx-homebrew.yaml osx
#generic
yaml file:///home/yourname/rosdistro/rosdep/base.yaml
yaml file:///home/yourname/rosdistro/rosdep/python.yaml
yaml file:///home/yourname/rosdistro/rosdep/ruby.yaml
gbpdistro file:///home/yourname/rosdistro/releases/fuerte.yaml
文件2
如果是ROS Noetic路径为python3, 如果是老版本在python2.7
cd /usr/lib/python3/dist-packages/rosdep2/
sudo gedit gbpdistro_support.py
同样替换
FUERTE_GBPDISTRO_URL = ‘file:///home/yourname/rosdistro/’
‘releases/fuerte.yaml’
sudo gedit /usr/lib/python3/dist-packages/rosdep2/rep3.py
同样替换
REP3_TARGETS_URL = ‘file:///home/yourname/rosdistro/releases/targets.yaml’
sudo gedit /usr/lib/python3/dist-packages/rosdistro/__init__.py
同样替换
cd DEFAULT_INDEX_URL = 'file:///home/yourname/rosdistro/index-v4.yaml'
第三步:
如果你已经使用了sudo rosdep init:
cd /etc/ros/rosdep/sources.list.d
sudo gedit 20-default.list
如果提示文件不存在,创建这个文件之后再使用上面的命令行
sudo mkdir -p /etc/ros/rosdep/sources.list.d
将下面的内容复制到文件并且保存
#os-specific listings first
yaml file:///home/yourname/rosdistro/rosdep/osx-homebrew.yaml osx
#generic
yaml file:///home/yourname/rosdistro/rosdep/base.yaml
yaml file:///home/yourname/rosdistro/rosdep/python.yaml
yaml file:///home/yourname/rosdistro/rosdep/ruby.yaml
gbpdistro file:///home/yourname/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
结果如下:
reading in sources list data from /etc/ros/rosdep/sources.list.d
Hit file:///home/yolo/rosdistro/rosdep/osx-homebrew.yaml
Hit file:///home/yolo/rosdistro/rosdep/base.yaml
Hit file:///home/yolo/rosdistro/rosdep/python.yaml
Hit file:///home/yolo/rosdistro/rosdep/ruby.yaml
Hit file:///home/yolo/rosdistro/releases/fuerte.yaml
Query rosdistro index file:///home/yolo/rosdistro/index-v4.yaml
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Skip end-of-life distro "crystal"
Add distro "dashing"
Skip end-of-life distro "eloquent"
Add distro "foxy"
Skip end-of-life distro "groovy"
Skip end-of-life distro "hydro"
Skip end-of-life distro "indigo"
Skip end-of-life distro "jade"
Add distro "kinetic"
Skip end-of-life distro "lunar"
Add distro "melodic"
Add distro "noetic"
Add distro "rolling"
updated cache in /home/yolo/.ros/rosdep/sources.cache
参考链接:
https://blog.csdn.net/leida_wt/article/details/115120940
https://blog.csdn.net/leida_wt/article/details/115120940
如果gitclone太慢,可以采用如下方法
``
git clone
git clone https://ghproxy.com/https://github.com/stilleshan/ServerStatus
wget & curl
wget https://ghproxy.com/https://github.com/stilleshan/ServerStatus/archive/master.zip
wget https://ghproxy.com/https://raw.githubusercontent.com/stilleshan/ServerStatus/master/Dockerfile
curl -O https://ghproxy.com/https://github.com/stilleshan/ServerStatus/archive/master.zip
curl -O https://ghproxy.com/https://raw.githubusercontent.com/stilleshan/ServerStatus/master/Dockerfile
欢迎关注转发
机器人研习社