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

catkin_make install fails due to: "Import Error: no module named `yaml`"

asked 2018-01-22 10:16:24 -0600

jnauta gravatar image

When following along with the Beginner Tutorial, I arrive at creating Messages and Services. However when I call catkin_make install inside the correct directory, I get the following error:

Traceback (most recent call last):
  File "/opt/ros/kinetic/share/genpy/cmake/../../../lib/genpy/", line 44, in <module>
    import genpy.generator
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/genpy/", line 34, in <module>
    from . message import Message, SerializationError, DeserializationError, MessageException, struct_I
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/genpy/", line 44, in <module>
    import yaml
ImportError: No module named 'yaml'
beginner_tutorials/CMakeFiles/beginner_tutorials_generate_messages_py.dir/build.make:64: recipe for target '/home/ros/catkin_ws/devel/lib/python3/dist-packages/beginner_tutorials/msg/' failed
make[2]: *** [/home/ros/catkin_ws/devel/lib/python3/dist-packages/beginner_tutorials/msg/] Error 1
CMakeFiles/Makefile2:519: recipe for target 'beginner_tutorials/CMakeFiles/beginner_tutorials_generate_messages_py.dir/all' failed
make[1]: *** [beginner_tutorials/CMakeFiles/beginner_tutorials_generate_messages_py.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make install -j1 -l1" failed

However yaml seems to be installed correctly, since I get no errors when using import yaml in a python script. There seems to be something fishy going on with the different versions of python though, since I get the following output for my $PYTHONPATH:


Where there is cleary some conflict between python3 and python2.

I am using Ubuntu 16.04 with ROS:Kinetic and a Virtual Environment with Python 2.7.12 and pip gives me the following for pyyaml:


whereas apt-get gives me

python-yaml is already the newest version (3.11-3build1)

Does anyone have any idea how to fix this?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-01-22 10:47:53 -0600

gvdhoorn gravatar image

updated 2018-01-23 04:08:51 -0600

ROS - even Kinetic - officially supports Python 2 only, so mixing and matching with Python 3 is going to be messy at best.

A virtualenv could work, but you'll have to make sure that it's completely isolated from your Python 3 install.


I believe that it was not stated that ROS only support Python 2

It will depend on how familiar you are with where this kind of info is typically found, but see REP-3 - Kinetic Kame.

See ros-infrastructure/rep#149 for some discussion about this (and how to handle the Python 3 migration).

I did the initial installation on a virtualenv running Python 3.

Did you install from sources or did you do a regular apt-get install?

edit flag offensive delete link more


Reinstalled ROS Kinetic without a virtualenv, so that Python 2 was the available version. I believe that it was not stated that ROS only support Python 2, so I did the initial installation on a virtualenv running Python 3. Problem seems to be solved now.

jnauta gravatar image jnauta  ( 2018-01-23 03:20:53 -0600 )edit

I did a regular apt-get install after using aft-get remove ros-* and removing some lingering directories.

jnauta gravatar image jnauta  ( 2018-01-23 05:44:22 -0600 )edit

My question was about your initial installation. The one you mention "on a virtualenv running Python 3".

Everything is hard-coded to Python 2 in the debians, so that's why I wondered whether you did a source install.

gvdhoorn gravatar image gvdhoorn  ( 2018-01-23 05:46:45 -0600 )edit

Ah I am sorry for misunderstanding. Since I assumed (wrongly) that ROS supported Python 3, I used a virtualenv which had Python 3 as it's main version of python; mkvirtualenv ROSenv --python=/usr/bin/python3. This generated the conflict since there was no Python 2 on that virtualenv.

jnauta gravatar image jnauta  ( 2018-01-23 05:58:31 -0600 )edit

Question Tools

1 follower


Asked: 2018-01-22 10:16:24 -0600

Seen: 3,355 times

Last updated: Jan 23 '18