最小linux系统下rosdep init和rosdepc init都更新失败的解决办法

本人用的开发板是迅为itop4412精英版SCP 1GB。CPU芯片是exynos4412。
本人在开发板上搭建了Linux最小系统,将gcc10.3.0编译器移植到开发板上运行后,本地编译安装了python2.7.18。
然后准备搭建ros环境。按官网上的说明来,先安装python的包管理器pip,然后看Generic (pip)那一栏:
pip install -U rosdep rosinstall_generator vcstool rosinstall
pip install --upgrade setuptools
这些都很顺利,然后rosdep init失败,网上查了一下是因为网站被封了,可以换装小鱼的rosdepc。

于是安装小鱼的rosdepc:
本文之后,世上再无rosdep更新失败问题!如果有....小鱼就...

然而换成rosdepc init也不行:

[root@exynos4412 opt]# rosdepc init
欢迎使用国内版rosdep之rosdepc
我是作者小鱼,学习机器人就关注公众号鱼香ROS

小鱼rosdepc正式为您服务---------------
ERROR: cannot download default sources list from:
https://gitee.com/ohhuo/rosdistro/raw/master/rosdep/sources.list.d/20-default.list
Website may be down.

强行用wget把20-default.list下载下来,放入/etc/ros/rosdep/sources.list.d文件夹。

wget能下载成功。然后执行rosdepc update:

[root@exynos4412 sources.list.d]# rosdepc update
欢迎使用国内版rosdep之rosdepc
我是作者小鱼,更多ROS学习资源请关注公众号鱼香ROS

小鱼rosdepc开始为您服务---------------
reading in sources list data from /etc/ros/rosdep/sources.list.d
Warning: running 'rosdepc update' as root is not recommended.
  You should run 'sudo rosdepc fix-permissions' and invoke 'rosdepc update' again without sudo.
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml]:
        <urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml]:
        <urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml]:
        <urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml]:
        <urlopen error [Errno 111] Connection refused> (https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml)
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml]:
        Failed to download target platform data for gbpdistro:
        <urlopen error [Errno 111] Connection refused>
Query rosdistro index https://gitee.com/ohhuo/rosdistro/raw/master/index-v4.yaml
ERROR: error loading sources list:
        <urlopen error <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:727)> (https://gitee.com/ohhuo/rosdistro/raw/master/index-v4.yaml)>



https://answers.ros.org/question/264262/rosdep-update-urlopen-error-ssl-certificate_verify_failed-certificate-verify-failed/
export SSL_CERT_FILE=/usr/lib/ssl/certs/ca-certificates.crt

注意到了最后有一个[SSL: CERTIFICATE_VERIFY_FAILED],可以确定就是python的问题。
在自己的文件夹下建立一个urltest.py文件试下:

import urllib2
url = "https://gitee.com/ohhuo/rosdistro/raw/master/index-v4.yaml"
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"}
request = urllib2.Request(url, headers = headers)
response = urllib2.urlopen(request)
print response.read()

运行,仍然是报[SSL: CERTIFICATE_VERIFY_FAILED]。

[root@exynos4412 python]# python urltest.py
Traceback (most recent call last):
  File "urltest.py", line 5, in <module>
    response = urllib2.urlopen(request)
  File "/usr/local/lib/python2.7/urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/lib/python2.7/urllib2.py", line 429, in open
    response = self._open(req, data)
  File "/usr/local/lib/python2.7/urllib2.py", line 447, in _open
    '_open', req)
  File "/usr/local/lib/python2.7/urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "/usr/local/lib/python2.7/urllib2.py", line 1241, in https_open
    context=self._context)
  File "/usr/local/lib/python2.7/urllib2.py", line 1198, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:727)>

复制python.py,粘贴并命名为urltest_unverified.py,内容修改为:

import urllib2
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
url = "https://gitee.com/ohhuo/rosdistro/raw/master/index-v4.yaml"
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"}
request = urllib2.Request(url, headers = headers)
response = urllib2.urlopen(request)
print response.read()

运行urltest_unverified.py,就能访问成功了。
奇怪的是,在电脑虚拟机上,urltest.py和urltest_unverified.py都能访问成功。
但嵌入式板子上,就只有urltest_unverified.py能访问成功。
后来笔者研究了半天,才知道是因为系统里面少了SSL_CERT_FILE环境变量,所以urltest.py执行不成功。

先在板子上用pip list命令检查一下,有没有装certifi这个包。笔者是在pip install requests的时候安装的certifi这个包。

[root@exynos4412 python]# pip install requests
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will remove support for this functionality.
Requirement already satisfied: requests in /usr/local/lib/python2.7/site-packages (2.26.0)
Requirement already satisfied: chardet<5,>=3.0.2; python_version < "3" in /usr/local/lib/python2.7/site-packages (from requests) (4.0.0)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python2.7/site-packages (from requests) (2021.5.30)
Requirement already satisfied: idna<3,>=2.5; python_version < "3" in /usr/local/lib/python2.7/site-packages (from requests) (2.10)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python2.7/site-packages (from requests) (1.26.6)

有了certifi这个包之后,执行python -m certifi命令就可以看到一个pem文件,我们只需要把这个pem文件导入到SSL_CERT_FILE环境变量里面,问题就解决了。

[root@exynos4412 python]# python -m certifi
/usr/local/lib/python2.7/site-packages/certifi/cacert.pem
[root@exynos4412 python]# export SSL_CERT_FILE=$(python -m certifi)
[root@exynos4412 python]# echo $SSL_CERT_FILE
/usr/local/lib/python2.7/site-packages/certifi/cacert.pem

好了,现在urltest.py在板子上也能执行成功了。
rosdepc init也能执行成功了。
可以把export SSL_CERT_FILE=$(python -m certifi)这句话放到/etc/profile里面,开机自动执行。

现在root用户下执行python urltest.py和rosdepc init没问题了,然而我们切换回普通用户,加上sudo执行sudo python urltest.py和sudo rosdepc init,又不行了,环境变量失效了。

解决方案一:
在sudo的时候传递一下环境变量的值:
sudo SSL_CERT_FILE=$SSL_CERT_FILE python urltest.py
sudo SSL_CERT_FILE=$SSL_CERT_FILE rosdepc init
或者加上-E选项:
sudo -E python urltest.py
sudo -E rosdepc init

解决方案二:
修改/etc/sudoers文件,强制保留$HOME和$SSL_CERT_FILE这两个环境变量,但$USER变量不保留(sudo模式下$USER必须为root)
sudo vi /etc/sudoers
把# Defaults env_keep += "HOME"前面的注释符号去掉
然后再加上Defaults env_keep += "SSL_CERT_FILE"
因为/etc/sudoers文件是只读文件,所以在vi编辑器里面需要加感叹号强制保存(:w!)


现在,rosdepc update还有一点问题,说不知道当前系统叫什么名字:


exynos4412 login: root
Password:

Processing /etc/profile... Done

[root@exynos4412 ~]# export SSL_CERT_FILE=$(python -m certifi)
[root@exynos4412 ~]# rosdepc init
欢迎使用国内版rosdep之rosdepc
我是作者小鱼,学习机器人就关注公众号鱼香ROS

小鱼rosdepc正式为您服务---------------
小鱼提示:你的系统已经存在该文件了,小鱼会为你删除并重新写入
Wrote /etc/ros/rosdep/sources.list.d/20-default.list
小鱼提示:恭喜你完成初始化,快点使用

 rosdepc update

更新吧
[root@exynos4412 ~]# rosdepc update
欢迎使用国内版rosdep之rosdepc
我是作者小鱼,更多ROS学习资源请关注公众号鱼香ROS

小鱼rosdepc开始为您服务---------------
reading in sources list data from /etc/ros/rosdep/sources.list.d
Warning: running 'rosdepc update' as root is not recommended.
  You should run 'sudo rosdepc fix-permissions' and invoke 'rosdepc update' again without sudo.
Hit https://gitee.com/ohhuo/rosdistro/raw/master/rosdep/osx-homebrew.yaml
Hit https://gitee.com/ohhuo/rosdistro/raw/master/rosdep/base.yaml
Hit https://gitee.com/ohhuo/rosdistro/raw/master/rosdep/python.yaml
Hit https://gitee.com/ohhuo/rosdistro/raw/master/rosdep/ruby.yaml
ERROR: unable to process source [https://gitee.com/ohhuo/rosdistro/raw/master/releases/fuerte.yaml]:
        Failed to download target platform data for gbpdistro:
        <urlopen error [Errno 111] Connection refused>
Query rosdistro index https://gitee.com/ohhuo/rosdistro/raw/master/index-v4.yaml
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"

ERROR: Rosdep experienced an error: Could not detect OS, tried ['zorin', 'windows', 'nixos', 'clearlinux', 'ubuntu', 'slackware', 'rocky', 'rhel', 'qnx', 'pop', 'osx', 'sailfishos', 'tizen', 'oracle', 'opensuse', 'opensuse', 'opensuse', 'opensuse', 'opensuse', 'openembedded', 'neon', 'mx', 'mint', 'linaro', 'gentoo', 'funtoo', 'freebsd', 'fedora', 'elementary', 'elementary', 'debian', 'cygwin', 'euleros', 'centos', 'manjaro', 'buildroot', 'arch', 'amazon', 'alpine', 'almalinux']
Please go to the rosdepc page [1] and file a bug report with the stack trace below.
[1] : http://www.ros.org/wiki/rosdepc

发生错误了,请关注微信公众号:鱼香ROS,找小鱼反馈哦

rosdepc version: 0.21.0

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/roscdep2/main.py", line 146, in rosdep_main
    exit_code = _rosdep_main(args)
  File "/usr/local/lib/python2.7/site-packages/roscdep2/main.py", line 446, in _rosdep_main
    return _no_args_handler(command, parser, options, args)
  File "/usr/local/lib/python2.7/site-packages/roscdep2/main.py", line 455, in _no_args_handler
    return command_handlers[command](options)
  File "/usr/local/lib/python2.7/site-packages/roscdep2/main.py", line 677, in command_update
    ros_distro=options.ros_distro)
  File "/usr/local/lib/python2.7/site-packages/roscdep2/sources_list.py", line 516, in update_sources_list
    rosdep_data = get_gbprepo_as_rosdep_data(dist_name)
  File "/usr/local/lib/python2.7/site-packages/roscdep2/gbpdistro_support.py", line 150, in get_gbprepo_as_rosdep_data
    ctx = create_default_installer_context()
  File "/usr/local/lib/python2.7/site-packages/roscdep2/__init__.py", line 91, in create_default_installer_context
    m.register_platforms(context)
  File "/usr/local/lib/python2.7/site-packages/roscdep2/platforms/debian.py", line 65, in register_platforms
    register_elementary(context)
  File "/usr/local/lib/python2.7/site-packages/roscdep2/platforms/debian.py", line 95, in register_elementary
    (os_name, os_version) = context.get_os_name_and_version()
  File "/usr/local/lib/python2.7/site-packages/roscdep2/installers.py", line 115, in get_os_name_and_version
    os_name = self.os_detect.get_name()
  File "/usr/local/lib/python2.7/site-packages/rospkg/os_detect.py", line 610, in get_name
    self.detect_os()
  File "/usr/local/lib/python2.7/site-packages/rospkg/os_detect.py", line 580, in detect_os
    raise OsNotDetected("Could not detect OS, tried %s" % attempted)
OsNotDetected: Could not detect OS, tried ['zorin', 'windows', 'nixos', 'clearlinux', 'ubuntu', 'slackware', 'rocky', 'rhel', 'qnx', 'pop', 'osx', 'sailfishos', 'tizen', 'oracle', 'opensuse', 'opensuse', 'opensuse', 'opensuse', 'opensuse', 'openembedded', 'neon', 'mx', 'mint', 'linaro', 'gentoo', 'funtoo', 'freebsd', 'fedora', 'elementary', 'elementary', 'debian', 'cygwin', 'euleros', 'centos', 'manjaro', 'buildroot', 'arch', 'amazon', 'alpine', 'almalinux']


[root@exynos4412 ~]#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

巨大八爪鱼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值