ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

trying to run a python script for robot

asked 2020-11-03 16:44:12 -0600

PGTKing gravatar image

updated 2021-01-13 22:47:26 -0600

jayess gravatar image

Hi ros community, I am trying to run a python script but I am getting this error: ImportError: No module named yaml After running rosrun rrbot_control in the terminal, I receive this.

Traceback (most recent call last):

  File "/home/brendan/catkin_ws/src/gazebo_ros_demos/rrbot_control/scripts/", line 3, in <module>
    import rospy

  File "/opt/ros/noetic/lib/python3/dist-packages/rospy/", line 47, in <module>
    from std_msgs.msg import Header

  File "/opt/ros/noetic/lib/python3/dist-packages/std_msgs/msg/", line 1, in <module>
    from ._Bool import *

  File "/opt/ros/noetic/lib/python3/dist-packages/std_msgs/msg/", line 6, in <module>
    import genpy

  File "/opt/ros/noetic/lib/python3/dist-packages/genpy/", line 34, in <module>
    from . message import Message, SerializationError, DeserializationError, MessageException, struct_I

  File "/opt/ros/noetic/lib/python3/dist-packages/genpy/", line 48, in <module>
    import yaml

ImportError: No module named yaml
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2020-11-03 16:50:41 -0600

Find the location of pip in your system by running the command 'which pip'.

Then, using your terminal, navigate to that location, and run 'pip install PyYAML'.

Hopefully, this should resolve the issue.

edit flag offensive delete link more


pip doesn't exist only pip3. When running pip3 instal PyYAML i get Requirement already satisfied: PyYAML in /usr/lib/python3/dist-packages (5.3.1)

PGTKing gravatar image PGTKing  ( 2020-11-03 17:23:05 -0600 )edit

Can you share the Python script that you are trying to run?

skpro19 gravatar image skpro19  ( 2020-11-04 07:46:57 -0600 )edit


#!/usr/bin/env python
# license removed for brevity

import rospy
from std_msgs.msg import Float64
import math

def talker():
    pub = rospy.Publisher('/rrbot/joint1_position_controller/command', Float64, queue_size=10)
    rospy.init_node('talker', anonymous=True)
    rate = rospy.Rate(10) # 10hz

    while not rospy.is_shutdown():
        #hello_str = "hello world %s" % rospy.get_time()

        position = 0.0

if __name__ == '__main__':
    except rospy.ROSInterruptException:
PGTKing gravatar image PGTKing  ( 2020-11-04 11:20:57 -0600 )edit

SOLVED!!!!!!!!!! changed python to python3 now works

PGTKing gravatar image PGTKing  ( 2020-11-04 14:52:39 -0600 )edit

Haha. Okay. I thought you had already set the keyword 'python' to point to 'python3' in your system.

skpro19 gravatar image skpro19  ( 2020-11-04 15:14:59 -0600 )edit

answered 2020-11-03 16:47:39 -0600

JackB gravatar image

Have you seen this question? I imagine it has something to do with you not having the proper python 3 package.

edit flag offensive delete link more


@JackB thanks, your tip helped me come to my conclusion

PGTKing gravatar image PGTKing  ( 2020-11-05 12:49:53 -0600 )edit

I am so glad I could help a tiny bit! good luck

JackB gravatar image JackB  ( 2020-11-05 13:34:58 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2020-11-03 16:44:12 -0600

Seen: 2,061 times

Last updated: Jan 13 '21