ROS2 Importerror:无法导入名称' generate_py'从' rosidl_generator_py'
我在尝试创建一个自定义界面的同时,按照ROS2教程创建自定义msg和srv文件。该项目看起来像这样:
src/tutorial_interfaces/
├── CMakeLists.txt
├── include
│ └── tutorial_interfaces
├── msg
│ └── Num.msg
├── package.xml
├── src
└── srv
└── AddThreeInts.srv
我遵循所有步骤,但是 步骤 5构建tutorial_interfaces软件包命令
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 Humble
I got an ImportError while trying to create a custom interface following the ros2 tutorial Creating custom msg and srv files. The project looks like this:
src/tutorial_interfaces/
├── CMakeLists.txt
├── include
│ └── tutorial_interfaces
├── msg
│ └── Num.msg
├── package.xml
├── src
└── srv
└── AddThreeInts.srv
I followed all steps but at
step 5 Build the tutorial_interfaces package the command
colcon build --packages-select tutorial_interfaces
failed with the following error message:
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'
Anyone has an idea how to resolve this?
System: Ubuntu 22.04 +
ROS2 Humble
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
通过安装依赖项来解决此问题,
我基本上查看了错误,并在位于此处的系统上看到了它是从
rosidl_generator_py
中导入generate_py
我 目录,启动Python,并尝试了
那里,我得到了有关错误的更多详细信息,错误基本上说我缺少Python依赖关系。
因此,您可能会缺少比我更多的依赖关系,如果是的话,请转到该目录并尝试自己导入它,口译员会告诉您您所缺少的内容。
I fixed this issue by installing dependencies
Basically I looked at the error and saw that it was importing
generate_py
fromrosidl_generator_py
, on my system that was located here:So I went to that directory, booted Python, and tried
There I got more details on the error, where the error basically said I was missing Python dependencies.
So you may be missing more dependencies than me, if so, go to that directory and try to import it yourself, and the interpreter will tell you what you are missing.
我面临同一问题(同一系统)
系统:Ubuntu 22.04 + ROS2 Humble
I'm Facing the same issue (same system)
System: Ubuntu 22.04 + ROS2 Humble
我在同一系统设置Ubuntu 22.04和Ros2 Humble上也有同样的问题。还有一件事是,我激活了Anaconda。我通过停用conda env并重新构建包装来解决问题。希望它可以帮助大家解决问题。
I have the same problem with the same system setup, Ubuntu 22.04 and ROS2 Humble. One more thing is I have anaconda activated. I solved the problem by deactivating conda env and re-build the package. Hopefully, it could help you guys to solve the problem.
最近,我在编译具有自定义接口定义的不同软件包时遇到了相同的错误。
我没有
anaconda
或conda
已安装,所以我无法脱离它。因此,我通过在cmakelists.txt
中评论此行来修复它:我敢肯定可能有更好的方法。但是我不确定是否有一种方法可以通过
colcon
使用哪种版本的Python,并且该版本是否可以导入generate_py
。I recently had the same error when compiling different packages that had custom interfaces definitions.
I don't have
anaconda
orconda
installed, so I cannot desactivate it. So I fixed it by commenting this line inCMakeLists.txt
:I'm sure there could be a better way. But I'm not sure if there is a way to debug which version of Python is used by
colcon
and whether or not that version can importgenerate_py
.