ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

trying to run a python script for robot

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

PGTKing gravatar image

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

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 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
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

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

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

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)

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

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

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

@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
PGTKing gravatar image PGTKing  ( 2020-11-04 11:20:57 -0500 )edit

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

PGTKing gravatar image PGTKing  ( 2020-11-04 14:52:39 -0500 )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 -0500 )edit
0

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

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

Comments

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

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

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

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

Question Tools

2 followers

Stats

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

Seen: 3,218 times

Last updated: Jan 13 '21