我无法将 Kivy 导入 ROS2

问题描述

我有一个问题,也许有人可以帮助我。 我试图用 ROS2 做一个应用程序。我为发布者和订阅者做了这个教程。 https://index.ros.org/doc/ros2/Tutorials/Writing-A-Simple-Py-Publisher-And-Subscriber/ 我的 GUI 使用 Kivy,并且必须将它导入到我的 Python 文件中。如果我导入 kivy,我会收到错误“ModuleNotFoundError: No module named 'kivy'” 为什么 ROS2 不接受 Kivy 导入?有人可以帮助我,我找不到解决方案。

这是我的 Python 文件

from rclpy.node import Node

from std_msgs.msg import String


import kivy








class MinimalSubscriber(Node):

    def __init__(self):
     #   TestApp().run
        super().__init__('minimal_subscriber')
        self.subscription = self.create_subscription(
            String,'topic',self.listener_callback,10)
        self.subscription  # prevent unused variable warning

    def listener_callback(self,msg):
        self.get_logger().info('I heard: "%s"' % msg.data)


def main(args=None):
   # TestApp().run
    rclpy.init(args=args)
    print("HELLO")

    minimal_subscriber = MinimalSubscriber()

    rclpy.spin(minimal_subscriber)

    # Destroy the node explicitly
    # (optional - otherwise it will be done automatically
    # when the garbage collector destroys the node object)
    minimal_subscriber.destroy_node()
    rclpy.shutdown()
    
    


if __name__ == '__main__':
    main() 

这就是我的 package.xml:

<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
  <name>py_pubsub</name>
  <version>0.0.0</version>
  <description>Examples of minimal publisher/subscriber using rclpy</description>
  <maintainer email="darius.schlese@yahoo.de">Darius</maintainer>
  <license>Apache License 2.0</license>

  <buildtool_depend>ament_python</buildtool_depend>
    
  <test_depend>ament_copyright</test_depend>
  <test_depend>ament_Flake8</test_depend>
  <test_depend>ament_pep257</test_depend>
  <test_depend>python3-pytest</test_depend>
  
  <build_depend>kivy</build_depend>
  <exec_depend>kivy</exec_depend>

  <export>
    <build_type>ament_python</build_type>
    <exec_depend>rclpy</exec_depend>
    <exec_depend>std_msgs</exec_depend>

    
  </export>
</package>

感谢您的帮助! :)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)