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

Problem with yaml

asked 2018-01-05 14:07:25 -0500

aefka gravatar image

Hi, I use ROS Indigo on Raspbian. When I try turn on a program, I have got error:

    Traceback (most recent call last):
  File "/home/pi/ros_catkin_ws/src/hil/scripts/hil.py", line 2, in <module>
    import rospy
  File "/home/pi/ros_catkin_ws/devel/lib/python2.7/dist-packages/rospy/__init__.py", line 35, in <module>
    exec(__fh.read())
  File "<string>", line 49, in <module>
  File "/home/pi/ros_catkin_ws/src/ros_comm/rospy/src/rospy/client.py", line 47, in <module>
    import yaml
ImportError: No module named 'yaml'

My program code is:

    #!/usr/bin/python3
import rospy
from std_msgs.msg import String
#added
from geometry_msgs.msg import Twist 


def callback(data):
    global msg
    if data.data=="Unknown":
        pub = rospy.Publisher('cmd_vel', Twist) 
        rospy.loginfo("Classifiers output: %s in unknown" % data.data)
        msg.linear.x = 2
        msg.linear.y = 2
        msg.angular.z = 0
        speed = 0.4 
        rospy.loginfo("checking for cmd" + str(msg.linear))
        pub.publish(msg)
    elif data.data=="Check":
        rospy.loginfo("Classifiers output: %s in check" % data.data)
    else:      
        rospy.loginfo("Classifiers output: %s and not unknown or check" % data.data)



def listener():

     global msg
     rospy.init_node('listener', anonymous=True)
     msg = Twist()
     rospy.Subscriber("ccc", String, callback)
     rospy.spin()


if __name__ == '__main__':



    listener()

I tried

sudo apt-get install python-yaml

yaml is installed, but error still appears

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-01-05 14:27:22 -0500

gvdhoorn gravatar image

You don't tell us which version of Raspbian you are using, but this is most likely a Python 2 vs Python 3 problem.

For typical platforms apt-get install python-yaml will install the Python 2 library.

From the shebang in your Python script:

#!/usr/bin/python3

you appear to run your script(s) using Python 3. As yaml is most likely not installed for that, the runtime can't find the module.

I suggest you switch to Python 2, as that is the default -- and best supported -- in all currently released ROS releases.

edit flag offensive delete link more

Comments

Note also btw that this is not really a ROS issue, but a regular Python / package installation one.

gvdhoorn gravatar image gvdhoorn  ( 2018-01-05 14:28:00 -0500 )edit

Very thanks, but my code still don't work, despite the error has disappeared. I wnat to publish msg. linear.x and msg.linear.y to V-REP to topic cmd_vel. I have no idea what i doing wrong :/

aefka gravatar image aefka  ( 2018-01-05 14:55:27 -0500 )edit

That would seem to be a different issue. I recommend you post a new question. This is not a forum, but a QA site, and those work best with a 1-to-1 ratio of questions and answers.

gvdhoorn gravatar image gvdhoorn  ( 2018-01-05 14:57:00 -0500 )edit

Question Tools

Stats

Asked: 2018-01-05 14:07:25 -0500

Seen: 2,369 times

Last updated: Jan 05 '18