Robotics StackExchange | Archived questions

trying to run a python script for robot

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 main.py in the terminal, I receive this.

Traceback (most recent call last):

  File "/home/brendan/catkin_ws/src/gazebo_ros_demos/rrbot_control/scripts/main.py", line 3, 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 6, 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 48, in <module>
    import yaml

ImportError: No module named yaml

Asked by PGTKing on 2020-11-03 17:44:12 UTC

Comments

Answers

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

Asked by JackB on 2020-11-03 17:47:39 UTC

Comments

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

Asked by PGTKing on 2020-11-05 13:49:53 UTC

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

Asked by JackB on 2020-11-05 14:34:58 UTC

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.

Asked by skpro19 on 2020-11-03 17:50:41 UTC

Comments

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)

Asked by PGTKing on 2020-11-03 18:23:05 UTC

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

Asked by skpro19 on 2020-11-04 08:46:57 UTC

@skpro19

#!/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
        rospy.loginfo(position)
        pub.publish(position)
        rate.sleep()


if __name__ == '__main__':
    try:
        talker()
    except rospy.ROSInterruptException:
        pass

Asked by PGTKing on 2020-11-04 12:20:57 UTC

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

Asked by PGTKing on 2020-11-04 15:52:39 UTC

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

Asked by skpro19 on 2020-11-04 16:14:59 UTC