Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Failed to launch rospy file: SyntaxError: invalid syntax YAMLObject(metaclass=YAMLObjectMetaclass):

Ask Question Traceback (most recent call last): File "/home/kwinklink/catkin_ws/src/turtlesim_cleaner1/src/turtlesim_cleaner1/rotate.py", line 2, in <module> import rospy File "/opt/ros/noetic/lib/python3/dist-packages/rospy/__init__.py", line 47, in <module> from std_msgs.msg import Header File "/opt/ros/noetic/lib/python3/dist-packages/std_msgs/msg/__init__.py", line 1, in <module> from ._Bool import * File "/opt/ros/noetic/lib/python3/dist-packages/std_msgs/msg/_Bool.py", line 5, in <module> import genpy File "/opt/ros/noetic/lib/python3/dist-packages/genpy/__init__.py", line 34, in <module> from . message import Message, SerializationError, DeserializationError, MessageException, struct_I File "/opt/ros/noetic/lib/python3/dist-packages/genpy/message.py", line 47, in <module> import yaml File "/usr/lib/python3/dist-packages/yaml/__init__.py", line 399 class YAMLObject(metaclass=YAMLObjectMetaclass): SyntaxError: invalid syntax

Here i have a picture of the error: enter image description here

I will appreciate any answers please help i have been workon on this error for a werry long time. In my rotate.py i onli have #!/usr/bin/env python import rospy

That's rather strange. The error indicates that the program is launched with Python 2 interpreter which does not support this metaclass syntax. But the traceback also shows that the libraries are installed with the Python 3 which supports this syntax. Sergey Shubin Jul 23, 2020 at 13:04 Yes, all i had to do was at the top of my script say #!/usr/bin/env python3 import rospy instead of #!/usr/bin/env python import rospy. Thanks! Kwinklink Dec 25, 2020 at 14:17 @Kwinklink I had the same error. Changing to #!/usr/bin/env python3 worked for me too. You should post it as a solution. Mint.High Apr 28, 2021 at 19:32

I found the solution!

Turns out all I had to do was to change #!/usr/bin/env python import rospy To: #!/usr/bin/env python3 import rospy

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question . Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers .