重要提示
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
已解决 重新运行代码时出现:UnsupportedTypeSupport: Could not import 'rosidl_typesupport_c' for package 'village_interfaces'
-
重新运行小鱼ros2课程中的代码,出现如题错误(之前可以运行),请问如何解决,谢谢!
ps:网上有同样问题,但没有解决
https://answers.ros.org/question/369159/could-not-import-rosidl_typesupport_c-for-package-packagename/
https://answers.ros.org/question/373256/ros2-could-not-import-rosidl_typesupport_c-for-package/andrew@ros2:~/town_ws$ ros2 run village_li li3_node [INFO] [1673964726.513490206] [li3]: 大家好,我是李三,李四他哥,我可以白嫖李四的小说! Traceback (most recent call last): File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_generator_py/import_type_support_impl.py", line 46, in import_type_support return importlib.import_module(module_name, package=pkg_name) File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1050, in _gcd_import File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 674, in _load_unlocked File "<frozen importlib._bootstrap>", line 571, in module_from_spec File "<frozen importlib._bootstrap_external>", line 1176, in create_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed ImportError: /home/andrew/town_ws/install/village_interfaces/lib/libvillage_interfaces__rosidl_generator_c.so: ELF file's phentsize not the expected size During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/andrew/town_ws/install/village_li/lib/village_li/li3_node", line 33, in <module> sys.exit(load_entry_point('village-li==0.0.0', 'console_scripts', 'li3_node')()) File "/home/andrew/town_ws/install/village_li/lib/python3.10/site-packages/village_li/li3.py", line 60, in main node = Li3Node("li3") # 新建一个节点 File "/home/andrew/town_ws/install/village_li/lib/python3.10/site-packages/village_li/li3.py", line 18, in __init__ self.borrow_client =self.create_client(BorrowMoney,"borrow_money") File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/node.py", line 1413, in create_client check_is_valid_srv_type(srv_type) File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/type_support.py", line 51, in check_is_valid_srv_type check_for_type_support(srv_type) File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/type_support.py", line 29, in check_for_type_support msg_or_srv_type.__class__.__import_type_support__() File "/home/andrew/town_ws/install/village_interfaces/local/lib/python3.10/dist-packages/village_interfaces/srv/_borrow_money.py", line 301, in __import_type_support__ module = import_type_support('village_interfaces') File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_generator_py/import_type_support_impl.py", line 48, in import_type_support raise UnsupportedTypeSupport(pkg_name) rosidl_generator_py.import_type_support_impl.UnsupportedTypeSupport: Could not import 'rosidl_typesupport_c' for package 'village_interfaces' [ros2run]: Process exited with failure 1
-
@andrew_liumuran 贴一下CmakeKList.txt 问题应该是没添加依赖造成的
BUG表现如下
自定义消息,编译不报错,运行就出错
Traceback (most recent call last):
File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_generator_py/import_type_support_impl.py", line 46, in import_type_support
return importlib.import_module(module_name, package=pkg_name)
File "/usr/lib/python3.8/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 657, in _load_unlocked
File "<frozen importlib._bootstrap>", line 556, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 1166, in create_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: /home/ros2/code/town_ws/install/village_interfaces/lib/libvillage_interfaces__rosidl_generator_c.so: undefined symbol: sensor_msgs__msg__Image__initDuring handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ros2/code/town_ws/install/village_li/lib/village_li/li4_node", line 11, in <module>
load_entry_point('village-li==0.0.0', 'console_scripts', 'li4_node')()
File "/home/ros2/code/town_ws/install/village_li/lib/python3.8/site-packages/village_li/li4.py", line 46, in main
node = Li4Node() # 新建一个节点
File "/home/ros2/code/town_ws/install/village_li/lib/python3.8/site-packages/village_li/li4.py", line 23, in init
self.borrow_server = self.create_service(BorrowMoney,"borrow_money",self.borrow_money_callback)
File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/node.py", line 1295, in create_service
check_for_type_support(srv_type)
File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/type_support.py", line 29, in check_for_type_support
msg_type.class.import_type_support()
File "/home/ros2/code/town_ws/install/village_interfaces/lib/python3.8/site-packages/village_interfaces/srv/_borrow_money.py", line 316, in import_type_support
module = import_type_support('village_interfaces')
File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_generator_py/import_type_support_impl.py", line 48, in import_type_support
raise UnsupportedTypeSupport(pkg_name)
rosidl_generator_py.import_type_support_impl.UnsupportedTypeSupport: Could not import 'rosidl_typesupport_c' for package 'village_interfaces'原因:
自定义消息未添加对其他消息的依赖解决办法,添加依赖在CMakeists.txt中
find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
#---msg---
"msg/Novel.msg"
#---srv---
"srv/BorrowMoney.srv"
"srv/SellNovel.srv"
DEPENDENCIES std_msgs sensor_msgs
)
————————————————
版权声明:本文为CSDN博主「鱼香ROS」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_27865227/article/details/119651587 -
@andrew_liumuran
类似的问题 链接文本 -
@andrew_liumuran 贴一下CmakeKList.txt 问题应该是没添加依赖造成的
BUG表现如下
自定义消息,编译不报错,运行就出错
Traceback (most recent call last):
File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_generator_py/import_type_support_impl.py", line 46, in import_type_support
return importlib.import_module(module_name, package=pkg_name)
File "/usr/lib/python3.8/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 657, in _load_unlocked
File "<frozen importlib._bootstrap>", line 556, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 1166, in create_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: /home/ros2/code/town_ws/install/village_interfaces/lib/libvillage_interfaces__rosidl_generator_c.so: undefined symbol: sensor_msgs__msg__Image__initDuring handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ros2/code/town_ws/install/village_li/lib/village_li/li4_node", line 11, in <module>
load_entry_point('village-li==0.0.0', 'console_scripts', 'li4_node')()
File "/home/ros2/code/town_ws/install/village_li/lib/python3.8/site-packages/village_li/li4.py", line 46, in main
node = Li4Node() # 新建一个节点
File "/home/ros2/code/town_ws/install/village_li/lib/python3.8/site-packages/village_li/li4.py", line 23, in init
self.borrow_server = self.create_service(BorrowMoney,"borrow_money",self.borrow_money_callback)
File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/node.py", line 1295, in create_service
check_for_type_support(srv_type)
File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/type_support.py", line 29, in check_for_type_support
msg_type.class.import_type_support()
File "/home/ros2/code/town_ws/install/village_interfaces/lib/python3.8/site-packages/village_interfaces/srv/_borrow_money.py", line 316, in import_type_support
module = import_type_support('village_interfaces')
File "/opt/ros/foxy/lib/python3.8/site-packages/rosidl_generator_py/import_type_support_impl.py", line 48, in import_type_support
raise UnsupportedTypeSupport(pkg_name)
rosidl_generator_py.import_type_support_impl.UnsupportedTypeSupport: Could not import 'rosidl_typesupport_c' for package 'village_interfaces'原因:
自定义消息未添加对其他消息的依赖解决办法,添加依赖在CMakeists.txt中
find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
#---msg---
"msg/Novel.msg"
#---srv---
"srv/BorrowMoney.srv"
"srv/SellNovel.srv"
DEPENDENCIES std_msgs sensor_msgs
)
————————————————
版权声明:本文为CSDN博主「鱼香ROS」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_27865227/article/details/119651587 -
@小鱼
小鱼您好,这是CmakeKList.txt,修改编译运行后仍有相同错误,还得麻烦您,谢谢!# /home/andrew/town_ws/src/village_interfaces/CMakeLists.txt cmake_minimum_required(VERSION 3.8) project(village_interfaces) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() # find dependencies find_package(ament_cmake REQUIRED) # uncomment the following section in order to fill in # further dependencies manually. # find_package(<dependency> REQUIRED) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) #添加对sensor_msgs的 find_package(sensor_msgs REQUIRED) find_package(rosidl_default_generators REQUIRED) # the following line skips the linter which checks for copyrights # comment the line when a copyright and license is added to all source files set(ament_cmake_copyright_FOUND TRUE) # the following line skips cpplint (only works in a git repo) # comment the line when this package is in a git repo and when # a copyright and license is added to all source files set(ament_cmake_cpplint_FOUND TRUE) ament_lint_auto_find_test_dependencies() endif() #添加消息文件和依赖 rosidl_generate_interfaces(${PROJECT_NAME} "msg/Novel.msg" "srv/BorrowMoney.srv" "srv/SellNovel.srv" DEPENDENCIES std_msgs sensor_msgs ) ament_package()
-
@andrew_liumuran 在 重新运行代码时出现:UnsupportedTypeSupport: Could not import 'rosidl_typesupport_c' for package 'village_interfaces' 中说:
#添加对sensor_msgs的
find_package(sensor_msgs REQUIRED)把这个移到
@andrew_liumuran 在 重新运行代码时出现:UnsupportedTypeSupport: Could not import 'rosidl_typesupport_c' for package 'village_interfaces' 中说:
if(BUILD_TESTING)
之前
-
小鱼您好,修改之后,还是相同的报错 谢谢您
project(village_interfaces) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() # find dependencies find_package(ament_cmake REQUIRED) find_package(sensor_msgs REQUIRED) find_package(std_msgs REQUIRED) find_package(rosidl_default_generators REQUIRED) # uncomment the following section in order to fill in # further dependencies manually. # find_package(<dependency> REQUIRED) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) #添加对sensor_msgs的 find_package(sensor_msgs REQUIRED) find_package(rosidl_default_generators REQUIRED) # the following line skips the linter which checks for copyrights # comment the line when a copyright and license is added to all source files set(ament_cmake_copyright_FOUND TRUE) # the following line skips cpplint (only works in a git repo) # comment the line when this package is in a git repo and when # a copyright and license is added to all source files set(ament_cmake_cpplint_FOUND TRUE) ament_lint_auto_find_test_dependencies() endif() #添加消息文件和依赖 rosidl_generate_interfaces(${PROJECT_NAME} "msg/Novel.msg" "srv/BorrowMoney.srv" "srv/SellNovel.srv" DEPENDENCIES std_msgs sensor_msgs ) ament_package()
以下是报错
andrew@ros2:~/town_ws$ ros2 run village_li li3_node [INFO] [1674031680.523058434] [li3]: 大家好,我是李三,李四他哥,我可以白嫖李四的小说! Traceback (most recent call last): File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_generator_py/import_type_support_impl.py", line 46, in import_type_support return importlib.import_module(module_name, package=pkg_name) File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1050, in _gcd_import File "<frozen importlib._bootstrap>", line 1027, in _find_and_load File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 674, in _load_unlocked File "<frozen importlib._bootstrap>", line 571, in module_from_spec File "<frozen importlib._bootstrap_external>", line 1176, in create_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed ImportError: /home/andrew/town_ws/install/village_interfaces/lib/libvillage_interfaces__rosidl_generator_c.so: ELF file's phentsize not the expected size During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/andrew/town_ws/install/village_li/lib/village_li/li3_node", line 33, in <module> sys.exit(load_entry_point('village-li==0.0.0', 'console_scripts', 'li3_node')()) File "/home/andrew/town_ws/install/village_li/lib/python3.10/site-packages/village_li/li3.py", line 60, in main node = Li3Node("li3") # 新建一个节点 File "/home/andrew/town_ws/install/village_li/lib/python3.10/site-packages/village_li/li3.py", line 18, in __init__ self.borrow_client =self.create_client(BorrowMoney,"borrow_money") File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/node.py", line 1413, in create_client check_is_valid_srv_type(srv_type) File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/type_support.py", line 51, in check_is_valid_srv_type check_for_type_support(srv_type) File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/type_support.py", line 29, in check_for_type_support msg_or_srv_type.__class__.__import_type_support__() File "/home/andrew/town_ws/install/village_interfaces/local/lib/python3.10/dist-packages/village_interfaces/srv/_borrow_money.py", line 301, in __import_type_support__ module = import_type_support('village_interfaces') File "/opt/ros/humble/local/lib/python3.10/dist-packages/rosidl_generator_py/import_type_support_impl.py", line 48, in import_type_support raise UnsupportedTypeSupport(pkg_name) rosidl_generator_py.import_type_support_impl.UnsupportedTypeSupport: Could not import 'rosidl_typesupport_c' for package 'village_interfaces' [ros2run]: Process exited with failure 1
-
@andrew_liumuran 把你的消息文件内容贴一下
-
/home/andrew/town_ws/src/village_interfaces/msg/Novel.msg
# 直接使用ROS2原始的数据类型 string content # 图像消息,调用sensor_msgs下的Image类型 sensor_msgs/Image image
-
@andrew_liumuran 看起来没啥问题, 改成这样试试
project(village_interfaces) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() # find dependencies find_package(ament_cmake REQUIRED) find_package(sensor_msgs REQUIRED) find_package(std_msgs REQUIRED) find_package(rosidl_default_generators REQUIRED) # uncomment the following section in order to fill in # further dependencies manually. # find_package(<dependency> REQUIRED) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) # the following line skips the linter which checks for copyrights # comment the line when a copyright and license is added to all source files set(ament_cmake_copyright_FOUND TRUE) # the following line skips cpplint (only works in a git repo) # comment the line when this package is in a git repo and when # a copyright and license is added to all source files set(ament_cmake_cpplint_FOUND TRUE) ament_lint_auto_find_test_dependencies() endif() #添加消息文件和依赖 rosidl_generate_interfaces(${PROJECT_NAME} "msg/Novel.msg" "srv/BorrowMoney.srv" "srv/SellNovel.srv" DEPENDENCIES std_msgs sensor_msgs ) ament_package()
另外还不行可以直接去掉
@andrew_liumuran 在 重新运行代码时出现:UnsupportedTypeSupport: Could not import 'rosidl_typesupport_c' for package 'village_interfaces' 中说:
sensor_msgs/Image image
-
@andrew_liumuran 另外记得把build和install目录删除掉,重新colcon build试试
-
謝謝小魚,刪除目錄有效,可以運行了!