**报错**:
2martin@martinComputer:~/ros2_ws$ ros2 run py_pubsub talker
Traceback (most recent call last):
File "/home/martin/ros2_ws/install/py_pubsub/lib/py_pubsub/talker", line 11, in <module>
load_entry_point('py-pubsub==0.0.0', 'console_scripts', 'talker')()
File "/home/martin/ros2_ws/install/py_pubsub/lib/python3.8/site-packages/py_pubsub/publisher_member_function.py", line 41, in main
minimal_publisher = MinimalPublisher()
File "/home/martin/ros2_ws/install/py_pubsub/lib/python3.8/site-packages/py_pubsub/publisher_member_function.py", line 25, in __init__
self.publisher_ = self.create_publisher(String, 'topic', 10)
File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/node.py", line 1144, in create_publisher
check_for_type_support(msg_type)
File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/type_support.py", line 20, in check_for_type_support
ts = msg_type.__class__._TYPE_SUPPORT
AttributeError: type object 'type' has no attribute '_TYPE_SUPPORT' This might be a ROS 1 message type but it should be a ROS 2 message type. Make sure to source your ROS 2 workspace after your ROS 1 workspace.
**原因**:在foxy tutorial官方教程中,package.xml使用的是<exec_depend>std_msgs</exec_depend>,这会导致只在运行时使用std_msgs。
**解决方法** : 修改为<depend>std_msgs</depend>
**反思**:他们的区别在于,depend实际包含了build_depend, build_export_depend 和 exec_depend,之前应该是使用ROS1有残留,所以切换之后应该制定编译依赖。在看到此类报错,应该就锁定string,看到string相关的就是<depend>std_msgs</depend>,所以排除错误。