Ask Your Question

ModuleNotFoundError: No module named 'yaml'

asked 2019-07-07 01:46:22 -0500

beliavskij gravatar image


I am only starting to learn ROS by attending Udemy course on it. Recently I have encountered a problem, when I try to run simple talker example using command:

rosrun ros_essentials_cpp

I receive an error:

    (base) ➜  catkin_ws rosrun ros_essentials_cpp
Traceback (most recent call last):
  File "/mnt/c/Users/daniu/Documents/Projects/ROS/catkin_ws/src/ros_essentials_cpp/src/topic01_basics/talker_listener/scripts/", line 3, in <module>
    import rospy
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/", line 47, in <module>
    from std_msgs.msg import Header
  File "/opt/ros/melodic/lib/python2.7/dist-packages/std_msgs/msg/", line 1, in <module>
    from ._Bool import *
  File "/opt/ros/melodic/lib/python2.7/dist-packages/std_msgs/msg/", line 5, in <module>
    import genpy
  File "/opt/ros/melodic/lib/python2.7/dist-packages/genpy/", line 34, in <module>
    from . message import Message, SerializationError, DeserializationError, MessageException, struct_I
  File "/opt/ros/melodic/lib/python2.7/dist-packages/genpy/", line 44, in <module>
    import yaml
ModuleNotFoundError: No module named 'yaml'

I tried to install yaml

python2.7 -m pip install pyyaml

Installation was successful, but it does not change anything

Previously I had no problems running ROS code (this too), but I have made a pause in my learning and after return, nothing is working

I am using WSL (Ubuntu 18.04 bionic)

Thank you for your help!

edit retag flag offensive close merge delete


Do you have any other Python interpreters / IDEs / runtime environments installed? Anaconda by any chance?

What is the output of which python and python -c 'import yaml'?

gvdhoorn gravatar image gvdhoorn  ( 2019-07-07 09:03:15 -0500 )edit

Yes, I do, I have an anaconda and my default Python is Python 3

(base) ➜  ~ python --version
Python 3.7.1

(base) ➜  ~ which python

(base) ➜  ~ python -c 'import yaml'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'yaml'

Is it a problem in their conflict? I was thinking about it, but did't find a way to resolve this

beliavskij gravatar image beliavskij  ( 2019-07-07 23:21:38 -0500 )edit

Yes, having Anaconda installed and having Python 3 the default is the cause of your problems.

There are many Q&As about this on this site. I suggest you search for them using Google (append to your query).

gvdhoorn gravatar image gvdhoorn  ( 2019-07-08 02:36:51 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2019-07-08 11:37:00 -0500

beliavskij gravatar image

Yes, I have found a solution that helped, it is described in this answer Using souce deactivate let my run the code Thank you

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-07-07 01:46:22 -0500

Seen: 8,810 times

Last updated: Jul 08 '19