【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 
    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 一下就好啦!

你可能感兴趣的:(ROS,python,linux)