Issue with importing yaml
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
Please show us the output from:
apt search python3-yaml
Please show us the output from:
echo $PYTHONPATH
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
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
?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. (':
If you are using the
print
statement in your python code, that has changed for python3. google it.