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

ModuleNotFoundError: No module named 'yaml'

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

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 -0600 )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 -0600 )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 -0600 )edit

2 Answers

Sort by » oldest newest most voted

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

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

answered 2022-10-14 03:11:46 -0600

peci1 gravatar image

This problem happens when the default python version launched by /usr/bin/env python3 is different version than the Ubuntu default Python (i.e., on Noetic/Focal, default is Python 3.8; if any other version launches by default, you get this issue).

This can happen because of many reasons. Some of them are being inside of a conda environment. Or Github Codespaces virtual machines also use a non-default python version.

edit flag offensive delete link more

Question Tools

1 follower


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

Seen: 9,843 times

Last updated: Oct 14 '22