【ROS】ImportError: cannot import name ‘generate_py‘ from ‘rosidl_generator_py‘ (/opt/ros/humble/local

主要报错如下:

--- stderr: examples_rclpy_pointcloud_publisher
/usr/lib/python3/dist-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
---
Finished <<< examples_rclpy_pointcloud_publisher [4.49s]
--- stderr: turtlesim                                 
Traceback (most recent call last):
  File "/opt/ros/humble/share/rosidl_generator_py/cmake/../../../lib/rosidl_generator_py/rosidl_generator_py", line 8, in <module>
    from rosidl_generator_py import generate_py
ImportError: cannot import name 'generate_py' from 'rosidl_generator_py' (/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_generator_py/__init__.py)
gmake[2]: *** [turtlesim__py/CMakeFiles/turtlesim__py.dir/build.make:121:rosidl_generator_py/turtlesim/_turtlesim_s.ep.rosidl_typesupport_fastrtps_c.c] 错误 1
gmake[1]: *** [CMakeFiles/Makefile2:706:turtlesim__py/CMakeFiles/turtlesim__py.dir/all] 错误 2
gmake[1]: *** 正在等待未完成的任务....
gmake: *** [Makefile:146:all] 错误 2
---
Failed   <<< turtlesim [27.0s, exited with code 2]

Summary: 22 packages finished [27.5s]
  1 package failed: turtlesim
  11 packages had stderr output: examples_rclpy_executors examples_rclpy_guard_conditions examples_rclpy_minimal_action_client examples_rclpy_minimal_action_server examples_rclpy_minimal_client examples_rclpy_minimal_publisher examples_rclpy_minimal_service examples_rclpy_minimal_subscriber examples_rclpy_pointcloud_publisher launch_testing_examples turtlesim

参考下面链接解决:

python - ROS2 ImportError: cannot import name 'generate_py' from 'rosidl_generator_py' - Stack Overflow

思路是:不能够import 包,原因可能有几个:

一个是,这个包不存在,或者是,缺少其他依赖库。但是ROS没有告诉我们缺少什么依赖库的,就是报错,import error。

所以,去报错提示的文件夹下面看看,是否存在这个文件,还是缺少其他python依赖。

然后发现这个文件是都有的,然后使用python 运行一下from rosidl_generator_py import generate_py,发现真的缺少依赖的。按照提示安装一下就好

这个报错提醒了我这一点,去提示的文件目录下检查一下,并在所在环境运行以检查相关报错。这主要原因还是因为ROS把python的报错也隐藏了,不能很好的知道报错是啥。

最后重新colcon build 一下就好啦!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值