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

Issue with importing yaml

asked 2021-08-02 03:31:17 -0500

nyla gravatar image

updated 2021-08-03 02:51:37 -0500

gvdhoorn gravatar image

Hello, I've been having the same issue with importing yaml when trying to run any python nodes on ros noetic. I'm using ros noetic on an Oracle VM VirtualBox virtual machine that runs on Ubuntu. I already have yaml downloaded, and I've also modified the permission to be executable by running the chmod command and I also included the line "#!/usr/bin/env python" at the start of my python node file.

 Traceback (most recent call last):
  File "/home/nyla/catkin_ws/src/hello_world/move_turtle.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 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

Comments

Please show us the output from: apt search python3-yaml

Please show us the output from: echo $PYTHONPATH

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-08-02 15:26:02 -0500 )edit

Hello, here is the information that you requested :

nyla@nyla-VirtualBox:~/catkin_ws$ apt search python3-yaml Sorting... Done Full Text Search... Done python3-yaml/focal-updates,focal-security,now 5.3.1-1ubuntu0.1 amd64 [installed,automatic]   YAML parser and emitter for Python3

python3-yaml-dbg/focal-updates,focal-security 5.3.1-1ubuntu0.1 amd64   YAML parser and emitter for Python3 (debug build)

python3-yamlordereddictloader/focal,focal 0.4.0-1 all   loader and dump for PyYAML keeping keys order

nyla@nyla-VirtualBox:~/catkin_ws$ echo $PYTHONPATH /opt/ros/noetic/lib/python3/dist-packages

nyla gravatar image nyla  ( 2021-08-02 23:45:22 -0500 )edit

Both of those look correct. On my Ubuntu 20 machine, #!/usr/bin/env python does not work because there is no /usr/bin/python app installed. If you have one, is it python2 or python3? Have you tried changing that first line to #!/usr/bin/env python3 ?

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-08-03 05:48:11 -0500 )edit

I've tried python3 instead of python3 and there is no longer an error, but now the issue lies with my talker node not printing anything on the screen. (':

nyla gravatar image nyla  ( 2021-08-04 01:41:53 -0500 )edit

If you are using the print statement in your python code, that has changed for python3. google it.

Mike Scheutzow gravatar image Mike Scheutzow  ( 2021-08-04 06:46:54 -0500 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2021-08-04 06:45:15 -0500

Mike Scheutzow gravatar image

updated 2021-08-04 06:52:25 -0500

It seems like you are using the python2 interpreter, not the python3 one. ros noetic requires that your rospy code use python3, so the "shell bang" line should be #!/usr/bin/env python3. If your code came from a older version of ros, there are code changes you'll likely need to use python3.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2021-08-02 03:31:17 -0500

Seen: 505 times

Last updated: Aug 04 '21