【问题标题】:ROS2 ImportError: cannot import name 'generate_py' from 'rosidl_generator_py'ROS2 ImportError:无法从 \'rosidl_generator_py\' 导入名称 \'generate_py\'
【发布时间】:2022-08-24 05:58:52
【问题描述】:

我在尝试按照 ros2 教程 Creating custom msg and srv files 创建自定义界面时遇到 ImportError。该项目如下所示:

src/tutorial_interfaces/
├── CMakeLists.txt
├── include
│   └── tutorial_interfaces
├── msg
│   └── Num.msg
├── package.xml
├── src
└── srv
    └── AddThreeInts.srv

我遵循了所有步骤,但在 步5 Build the tutorial_interfaces package命令

colcon build --packages-select tutorial_interfaces

失败并显示以下错误消息:

Starting >>> tutorial_interfaces
--- stderr: tutorial_interfaces                             
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\'

任何人都知道如何解决这个问题?

系统:Ubuntu 22.04 + ROS2 谦虚

    标签: python ros ros2


    【解决方案1】:

    我面临同样的问题(相同的系统)

    系统:Ubuntu 22.04 + ROS2 Humble

    colcon build                                                                                          ─╯
    [0.370s] WARNING:colcon.colcon_core.package_selection:Some selected packages are already built in one or more underlay workspaces:
        'turtlesim' is in: /opt/ros/humble
    If a package in a merged underlay workspace is overridden and it installs headers, then all packages in the overlay must sort their include directories by workspace order. Failure to do so may result in build failures or undefined behavior at run time.
    If the overridden package is used by another package in any underlay, then the overriding package in the overlay must be API and ABI compatible or undefined behavior at run time may occur.
    
    If you understand the risks and want to override a package anyways, add the following to the command line:
        --allow-overriding turtlesim
    
    This may be promoted to an error in a future release of colcon-override-check.
    Starting >>> turtlesim
    --- 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] Error 1
    gmake[1]: *** [CMakeFiles/Makefile2:706: turtlesim__py/CMakeFiles/turtlesim__py.dir/all] Error 2
    gmake[1]: *** Waiting for unfinished jobs....
    gmake: *** [Makefile:146: all] Error 2
    ---
    Failed   <<< turtlesim [0.48s, exited with code 2]
    
    Summary: 0 packages finished [0.64s]
      1 package failed: turtlesim
      1 package had stderr output: turtlesim
    

    【讨论】:

      【解决方案2】:

      同样的,使用相同的系统:Ubuntu 22.04 + ROS2 Humble。关于这个问题的任何更新?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-22
        • 2021-06-30
        • 2020-10-19
        • 2018-08-13
        • 2015-01-26
        • 2020-10-10
        • 2020-02-12
        • 2021-11-27
        相关资源
        最近更新 更多