Search code examples
pythonrosros2

ROS2: ImportError: No module named genmsg


I starting with ROS2 which is currently in the alpha phase. While building the package ros1_bridge I got this error:

Traceback (most recent call last):
  File "bin/ros1_bridge_generate_factories", line 11, in <module>
    from ros1_bridge import generate_cpp
  File "/home/ros/ros2_ws/src/ros2/ros1_bridge/ros1_bridge/__init__.py", line 13, in <module>
    import genmsg
ImportError: No module named 'genmsg'

This is quite strange. On the same computer I build the same code without any problem. The only thing that changed: I have installed ROS Kinetic.

I found out in synaptic that I have now two different packages of genmsg installed: python-genmsg and ros-kinetic-genmsg. The first one comes as dependency of ROS2 the second one with ROS. So may both are necessary. I think that is Python-stuff and I am not familiar with Python. What can I do to get it run again?


Solution

  • This happens while dependencies installed for ROS and ROS2 on the same machine. Especially the package python-genmsg and ros-kinetic-genmsg. genmsg can now found at these places:

    1. /opt/ros/kinetic/lib/python2.7/dist-packages
    2. /usr/lib/python2.7/dist-packages

    This will bring Python run into trouble. In respect that ros1_bridge shall fit to ROS Kinetic the environment Python variable PYTHONPATH will set to the Kinetic one:

    export PYTHONPATH=/opt/ros/kinetic/lib/python2.7/dist-packages/
    

    Now restart the build and the build runs now...