解决sudo rosdep init和rosdep update各种疑难杂症

问题描述:

环境:ubuntu18+ROS molodic full-desktop
在安装ROS的时候,最后两步骤sudo rosdep init和rosdep update出现各种问题,以此记录各种疑难杂症的解决方案。

一、sudo rosdep init

Error1:ERROR: cannot download default sources list from:

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.

解决:
ping该网址,发现能ping通

ping raw.githubusercontent.com

PING raw.githubusercontent.com (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.012 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.011 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.016 ms
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.010 ms
64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.011 ms
64 bytes from localhost (127.0.0.1): icmp_seq=6 ttl=64 time=0.013 ms
64 bytes from localhost (127.0.0.1): icmp_seq=7 ttl=64 time=0.014 ms
^C
--- raw.githubusercontent.com ping statistics ---

因此,于是修改hosts文件,加入以下两个网址的IP地址实现访问。

sudo gedit /etc/hosts

199.232.28.133 raw.githubusercontent.com
151.101.228.133 raw.github.com

Error2:ERROR: default sources list file already exists:

解决了上一个问题后,继续执行,会有新的报错

sudo rosdep init 
ERROR: default sources list file already exists:
	/etc/ros/rosdep/sources.list.d/20-default.list
Please delete if you wish to re-initialize
(base) twilight@pc: /etc/ros/rosdep/sources

原因及解决:由于已经生成了20-default.list,报错中提示需要删除,因此删除后再执行。

sudo rm 20-default.list
sudo rosdep init 

Error3:ERROR: Rosdep experienced an error: (‘The read operation timed out’,) / SSLError: (‘The read operation timed out’,)

解决了上一个问题后,继续执行,会有新的报错

(base) twilight@pc: /etc/ros/rosdep/sources.list.d$ sudo rosdep init

ERROR: Rosdep experienced an error: ('The read operation timed out',)
Please go to the rosdep page [1] and file a bug report with the stack trace below.
[1] : http://www.ros.org/wiki/rosdep

rosdep version: 0.21.0

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/rosdep2/main.py", line 146, in rosdep_main
    exit_code = _rosdep_main(args)
  File "/usr/lib/python2.7/dist-packages/rosdep2/main.py", line 441, in _rosdep_main
    return _no_args_handler(command, parser, options, args)
  File "/usr/lib/python2.7/dist-packages/rosdep2/main.py", line 450, in _no_args_handler
    return command_handlers[command](options)
  File "/usr/lib/python2.7/dist-packages/rosdep2/main.py", line 594, in command_init
    data = download_default_sources_list()
  File "/usr/lib/python2.7/dist-packages/rosdep2/sources_list.py", line 340, in download_default_sources_list
    f = urlopen(url, timeout=DOWNLOAD_TIMEOUT)
  File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 429, in open
    response = self._open(req, data)
  File "/usr/lib/python2.7/urllib2.py", line 447, in _open
    '_open', req)
  File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.7/urllib2.py", line 1248, in https_open
    context=self._context)
  File "/usr/lib/python2.7/urllib2.py", line 1208, in do_open
    r = h.getresponse(buffering=True)
  File "/usr/lib/python2.7/httplib.py", line 1178, in getresponse
    response.begin()
  File "/usr/lib/python2.7/httplib.py", line 452, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.7/httplib.py", line 408, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "/usr/lib/python2.7/socket.py", line 480, in readline
    data = self._sock.recv(self._rbufsize)
  File "/usr/lib/python2.7/ssl.py", line 754, in recv
    return self.read(buflen)
  File "/usr/lib/python2.7/ssl.py", line 641, in read
    v = self._sslobj.read(len)
SSLError: ('The read operation timed out',)

解决:
1.在~/.bashrc中添加一句conda deactivate

code  ~/.bashrc
conda deactivate

2.延长timeout

sudo pip install --upgrade -i https://pypi.tuna.tsinghua.edu.cn/simple pip
pip --default-timeout=100 install django

至此,第一步rosdep init解决。

二、rosdep update

在运行rosdep update时会出现(‘The read operation timed out’,)的报错,这是由于网络原因,访问超时。

$ 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
ERROR: error loading sources list:
	('The read operation timed out',)

解决:
用proxychains挂命令行agejt
对于怎么设置proxychains,见博主另一篇博文:
命令行 agent: proxychains配置
解决ROS中rosdep update超时的问题

$ proxychains rosdep update
ProxyChains-3.1 (http://proxychains.sf.net)
reading in sources list data from /etc/ros/rosdep/sources.list.d
|S-chain|-<>-127.0.0.1:1080-<><>-199.232.28.133:443-<><>-OK
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
|DNS-request| raw.githubusercontent.com 
|S-chain|-<>-127.0.0.1:1080-<><>-4.2.2.2:53-<><>-OK
|DNS-response| raw.githubusercontent.com is 185.199.108.133
|S-chain|-<>-127.0.0.1:1080-<><>-185.199.108.133:443-<><>-OK
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
|DNS-request| raw.githubusercontent.com 
|S-chain|-<>-127.0.0.1:1080-<><>-4.2.2.2:53-<><>-OK
|DNS-response| raw.githubusercontent.com is 185.199.111.133
|S-chain|-<>-127.0.0.1:1080-<><>-185.199.111.133:443-<><>-OK
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
|DNS-request| raw.githubusercontent.com 
|S-chain|-<>-127.0.0.1:1080-<><>-4.2.2.2:53-<><>-OK
|DNS-response| raw.githubusercontent.com is 185.199.110.133
|S-chain|-<>-127.0.0.1:1080-<><>-185.199.110.133:443-<><>-OK
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
|DNS-request| raw.githubusercontent.com 
|S-chain|-<>-127.0.0.1:1080-<><>-4.2.2.2:53-<><>-OK
|DNS-response| raw.githubusercontent.com is 185.199.111.133
|S-chain|-<>-127.0.0.1:1080-<><>-185.199.111.133:443-<><>-OK
|DNS-request| raw.githubusercontent.com 
|S-chain|-<>-127.0.0.1:1080-<><>-4.2.2.2:53-<><>-OK
|DNS-response| raw.githubusercontent.com is 185.199.109.133
|S-chain|-<>-127.0.0.1:1080-<><>-185.199.109.133:443-<><>-OK
Hit https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
|DNS-request| raw.githubusercontent.com 
|S-chain|-<>-127.0.0.1:1080-<><>-4.2.2.2:53-<><>-OK
|DNS-response| raw.githubusercontent.com is 185.199.111.133
|S-chain|-<>-127.0.0.1:1080-<><>-185.199.111.133:443-<><>-OK
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Skip end-of-life distro "crystal"
Skip end-of-life distro "dashing"
Skip end-of-life distro "eloquent"
Add distro "foxy"
|DNS-request| raw.githubusercontent.com 
|S-chain|-<>-127.0.0.1:1080-<><>-4.2.2.2:53-<><>-OK
|DNS-response| raw.githubusercontent.com is 185.199.110.133
|S-chain|-<>-127.0.0.1:1080-<><>-185.199.110.133:443-<><>-OK
Add distro "galactic"
|DNS-request| raw.githubusercontent.com 
|S-chain|-<>-127.0.0.1:1080-<><>-4.2.2.2:53-<><>-OK
|DNS-response| raw.githubusercontent.com is 185.199.110.133
|S-chain|-<>-127.0.0.1:1080-<><>-185.199.110.133:443-<><>-OK
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"
|DNS-request| raw.githubusercontent.com 
|S-chain|-<>-127.0.0.1:1080-<><>-4.2.2.2:53-<><>-OK
|DNS-response| raw.githubusercontent.com is 185.199.108.133
|S-chain|-<>-127.0.0.1:1080-<><>-185.199.108.133:443-<><>-OK
Add distro "noetic"
|DNS-request| raw.githubusercontent.com 
|S-chain|-<>-127.0.0.1:1080-<><>-4.2.2.2:53-<><>-OK
|DNS-response| raw.githubusercontent.com is 185.199.108.133
|S-chain|-<>-127.0.0.1:1080-<><>-185.199.108.133:443-<><>-OK
Add distro "rolling"
|DNS-request| raw.githubusercontent.com 
|S-chain|-<>-127.0.0.1:1080-<><>-4.2.2.2:53-<><>-OK
|DNS-response| raw.githubusercontent.com is 185.199.109.133
|S-chain|-<>-127.0.0.1:1080-<><>-185.199.109.133:443-<><>-OK
updated cache in /home/twilight/.ros/rosdep/sources.cache
twilight@pc: /etc/ros/rosdep/sources.list.d$ 

相关链接:
rosdep init ROS安装问题解决方案
“SSLError: The read operation timed out” when using pip

<think>我们正在处理用户关于在执行 `sudo rosdep init && rosdep update` 时遇到 `sudo: rosdep: command not found` 错误的问题。根据提供的引用常见解决方案,我们可以按照以下步骤来解决。 首先,这个错误表明系统无法找到 `rosdep` 命令。这通常是因为 `rosdep` 没有被正确安装或者其路径没有被包含在环境变量中。在ROS安装过程中,`rosdep` 是作为一个工具被安装的,但有时可能因为安装不完整或环境配置问题导致。 根据引用[2]引用[4],我们可以尝试以下步骤: 1. 确保已经安装了 `python-rosdep` 包(对于Ubuntu 18.04,如果是其他版本,包名可能略有不同)。在Ubuntu 18.04中,可以使用以下命令安装: ``` sudo apt-get install python-rosdep ``` 对于较新的Ubuntu版本(如20.04或22.04),可能需要使用 `python3-rosdep`,即: ``` sudo apt install python3-rosdep ``` 2. 如果已经安装或者安装后仍然出现同样的问题,那么可能是因为 `rosdep` 的路径没有被加入到环境变量中。但是,通常安装包时会自动处理可执行文件的路径(例如放在`/usr/bin/`下)。我们可以检查一下是否存在 `rosdep` 可执行文件: ``` which rosdep ``` 或者 ``` ls /usr/bin/ | grep rosdep ``` 3. 如果没有找到,可能需要重新安装或者检查安装过程。另外,引用[4]中提到使用国内镜像源安装ROS,这可以避免网络问题。但这里的问题是没有找到命令,所以重点在安装 `rosdep` 工具本身。 4. 如果安装 `python-rosdep` 后问题依旧,可以尝试初始化 `rosdep` 而不使用 `sudo`(但通常需要sudo权限),或者检查权限问题。不过,错误信息是“command not found”,所以主要还是路径问题。 5. 另外,引用[3]中提到了一些其他可能的解决方法,比如网络问题,但这里我们的问题是命令未找到,所以先解决安装问题。 6. 还有一种可能是ROS没有完全安装。在安装ROS时,通常我们会安装一个完整版(如 `ros-melodic-desktop-full`)或者基础版。在安装ROS时,`rosdep` 是作为ROS的一部分被安装的,但有时可能因为安装命令不包含这个工具。因此,我们可以尝试重新安装ROS的相关包。 综合以上,我们给出以下步骤: 步骤1:安装 `rosdep` 包 对于Ubuntu 18.04 (ROS Melodic): sudo apt-get install python-rosdep 对于Ubuntu 20.04 (ROS Noetic) 或更高版本: sudo apt install python3-rosdep 步骤2:如果步骤1完成,再次尝试运行命令: sudo rosdep init 如果仍然出现同样的错误,那么可能是安装的 `rosdep` 没有在标准路径下。我们可以尝试查找 `rosdep` 的位置: 步骤3:查找 `rosdep` 的位置 使用 `find` 命令: sudo find / -name rosdep 2>/dev/null 假设我们找到了一个路径,例如 `/usr/lib/python2.7/dist-packages/rosdep2/`,但是注意,我们需要的可执行文件通常是在某个 `bin` 目录下。实际上,`rosdep` 的可执行文件可能位于 `/usr/bin/rosdep` 或 `/usr/local/bin/rosdep`。 步骤4:如果发现 `rosdep` 不在 `/usr/bin/` 等标准路径,我们可以创建一个符号链接: sudo ln -s <找到的rosdep的完整路径> /usr/bin/rosdep 例如,如果在 `/usr/lib/python2.7/dist-packages/rosdep2/main.py` 找到了一个python脚本,我们可以这样: sudo ln -s /usr/lib/python2.7/dist-packages/rosdep2/main.py /usr/bin/rosdep 但是注意,通常安装 `python-rosdep` 后,应该会在 `/usr/bin/rosdep` 有一个可执行文件。如果没有,可能是安装有问题。 步骤5:如果上述步骤都无法解决,考虑重新安装ROS。特别是如果ROS是刚刚安装,可能安装不完整。可以尝试重新安装ROS的桌面完整版(以Melodic为例): sudo apt install ros-melodic-desktop-full 然后再次尝试安装 `rosdep`。 步骤6:如果重新安装ROS后,仍然没有 `rosdep`,可以尝试通过 `ros` 的初始化脚本来设置环境。有时候,`rosdep` 可能被安装在ROS的环境路径中(比如在 `/opt/ros/melodic/bin` 下),而这个路径可能不在普通用户的PATH中。我们可以通过source ROS的setup.bash来添加路径: source /opt/ros/melodic/setup.bash 然后尝试运行 `rosdep`。如果这样能运行,那么我们可以将这一行添加到 `~/.bashrc` 中,以便每次启动终端时自动设置。 但是,请注意,`rosdep` 通常被设计为系统级工具,安装到 `/usr/bin`,所以这个问题比较少见。 综上所述,我们优先尝试安装 `python-rosdep`(或 `python3-rosdep`)这个包。如果已经安装,尝试重新安装。 根据引用[2]中的方法,我们可以尝试安装 `python-rosdep` 来解决。 因此,针对用户的问题,我们给出如下解答: </think>### 解决 `sudo: rosdep: command not found` 错误的方法 执行 `sudo rosdep init && rosdep update` 时出现 `command not found` 错误,通常是因为 **`rosdep` 工具未正确安装** 或 **环境配置问题**。以下是逐步解决方案: #### 步骤 1:安装 ROS 依赖管理工具 --- ```bash # Ubuntu 18.04 (ROS Melodic) sudo apt-get install python-rosdep # Ubuntu 20.04/22.04 (ROS Noetic/Foxy) sudo apt-get install python3-rosdep ``` ⚠️ **关键说明**: 若提示 `python-rosdep not found`,尝试替换为 `ros-<distro>-rosdep`(如 `ros-melodic-rosdep`) 安装后验证:`which rosdep` 应返回路径(如 `/usr/bin/rosdep`)[^2][^4] #### 步骤 2:修复环境变量 --- ```bash # 加载 ROS 环境(替换 melodic 为你的 ROS 版本) source /opt/ros/melodic/setup.bash # 永久生效:将上行命令添加到 ~/.bashrc echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc source ~/.bashrc ``` #### 步骤 3:手动初始化(可选) --- 若仍报错,尝试手动创建配置文件: ```bash sudo mkdir -p /etc/ros/rosdep/sources.list.d/ echo "yaml https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx" | sudo tee /etc/ros/rosdep/sources.list.d/20-default.list ``` #### 步骤 4:执行初始化与更新 --- ```bash sudo rosdep init # 需输入密码 rosdep update # 无需 sudo ``` 💡 **注意**: - 使用国内镜像加速(若网络超时): ```bash export ROSDISTRO_INDEX_URL=https://mirrors.tuna.tsinghua.edu.cn/rosdistro/ rosdep update ``` #### 常见排查点 1. **安装完整性**:确认完整安装 ROS 基础包 `sudo apt install ros-<distro>-desktop-full` 2. **权限问题**:避免在虚拟环境中操作,使用 `sudo -E` 保留环境变量 3. **文件残留**:删除旧配置 `sudo rm -rf /etc/ros/rosdep/` 后重试[^3] > 通过上述步骤,95% 的 `command not found` 错误可解决。若仍失败,建议检查 [ROS 官方安装文档](https://wiki.ros.org/) 或替换软件源[^4]。
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值