ROS2安装问题记录

发布于:2024-05-04 ⋅ 阅读:(27) ⋅ 点赞:(0)

0. import rclpy出错

安装ros2官网上的教程安装完,发现colcon build后可以通过ros2 run 运行,但是无法通过python直接运行.py文件,原因是在 import rclpy的情况下会报以下错误

The C extension '/opt/ros/humble/lib/python3.10/site-packages/_rclpy_pybind11.cpython-311-x86_64-linux-gnu.so' isn't present on the system. 

然后就对rclpy进行了源码的安装,遇到了一些问题,在此记录。

解决方法:

目前看来因为安装了conda环境,conda的python版本和rclpy的python版本不一致导致;

rclpy 使用humble对应 python3.10 

1. rclpy 源码安装

——————————————————————————————————————————

按照github上的代码运行,发现在colcon build 过程中报了一堆类似以下的错误

fatal error: rcl/service_introspection.h: 没有那个文件或目录

/usr/include/pybind11/detail/type_caster_base.h:482:26: error: invalid use of incomplete type ‘PyFrameObject’ {aka ‘struct _frame’}
 

解决方法:

rclpy版本 与 ubuntu版本 和python 版本强相关,我的电脑是ubuntu22.04, 对应的ros2版本(即rclpy版本)是humble,需要将github上clone下来的代码切换到humble分支,然后再按照README重新运行

cd rclpy
git checkout -b humble   remotes/origin/humble

——————————————————————————————————————————

/usr/include/pybind11/detail/common.h:215:10: fatal error: Python.h: 没有那个文件或目录

解决方法:
sudo apt install python3-sphinx python3-pip
sudo -H pip3 install sphinx_autodoc_typehints

___________________________________________________________________________

ModuleNotFoundError: No module named 'catkin_pkg'

解决方法:
pip install catkin_pkg

————————————————— 

2. rclpy 运行

import rclpy的时候

/home/zjlab/anaconda3/ros2/bin/../lib/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/_rclpy_pybind11.cpython-310-x86_64-linux-gnu.so)

解决方法:

ubuntu 22.04 自带的gcc 版本是11.4.0, 这里需要安装gcc 12版本

如何是conda环境,运行

conda install -c conda-forge gcc=12.1.0

或者如果是直接是系统的python的话,可能可以升级g++版本

sudo apt-get install gcc-12 g++-12 #安装

ls /usr/bin/gcc*  
#查看gcc版本

'''
切换优先级
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 100
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 80
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 80


sudo update-alternatives --config gcc
sudo update-alternatives --config g++
'''

然后建立软链接,从系统libstdc++.so.6 链接到conda环境下

ln -s /usr/lib/x86_64-linux-gnu/libstdc++.so.6 /home/zjlab/anaconda3/envs/ros2/bin/../lib/libstdc++.so.6

 

3. 自定义msg和srv后的编译问题 

按照官网

先后报了以下的错误

ModuleNotFoundError: No module named 'em'
AttributeError: module 'em' has no attribute 'BUFFERED_OPT'
 

解决方法:
pip install empy==3.3.4

 安装完后把install/和build/ 文件夹删除重新编译。

——————————————————————————————————————————

ModuleNotFoundError: No module named 'lark'

解决方法:
pip install lark


网站公告

今日签到

点亮在社区的每一天
去签到