0
$\begingroup$

Rosanswers logo

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/genmsg_py.py", line 44, in <module>
    import genpy.generator
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/genpy/__init__.py", line 34, in <module>
    from . message import Message, SerializationError, DeserializationError, MessageException, struct_I
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/genpy/message.py", 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/_Num.py' failed
make[2]: *** [/home/ros/catkin_ws/devel/lib/python3/dist-packages/beginner_tutorials/msg/_Num.py] 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:

/home/ros/catkin_ws/devel/lib/python3/dist-packages:/opt/ros/kinetic/lib/python2.7/dist-packages

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:

/home/.virtualenvs/ros/lib/python2.7/site-packages

whereas apt-get gives me

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

Does anyone have any idea how to fix this?


Originally posted by jnauta on ROS Answers with karma: 3 on 2018-01-22

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Edit:

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?


Originally posted by gvdhoorn with karma: 86574 on 2018-01-22

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by jnauta on 2018-01-23:
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.

Comment by jnauta on 2018-01-23:
I did a regular apt-get install after using aft-get remove ros-* and removing some lingering directories.

Comment by gvdhoorn on 2018-01-23:
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.

Comment by jnauta on 2018-01-23:
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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.