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

<class 'ModuleNotFoundError'>: No module named 'genmsg'

asked 2022-02-09 13:58:26 -0500

ticotico gravatar image

Dear community

I am trying to build ROS noetic from source on a raspberry pi with the most recent OctoPi image. I concluded that I had to do an installation from source (please correct me if that assumption is wrong) and now I am stuck while building the workspace with catkin build. The relevant part:

pi@octopi:~/catkin_ws/src/std_msgs $ catkin build --this
Profile:                     default
Extending:                   None
Workspace:                   /home/pi/catkin_ws
Build Space:        [exists] /home/pi/catkin_ws/build
Devel Space:        [exists] /home/pi/catkin_ws/devel
Install Space:      [exists] /home/pi/catkin_ws/install
Log Space:          [exists] /home/pi/catkin_ws/logs
Source Space:       [exists] /home/pi/catkin_ws/src
DESTDIR:            [unused] None
Devel Space Layout:          linked
Install Space Layout:        merged
Additional CMake Args:       -DCMAKE_BUILD_TYPE=Release
Additional Make Args:        None
Additional catkin Make Args: None
Internal Make Job Server:    True
Cache Job Environments:      False
Whitelisted Packages:        None
Blacklisted Packages:        None

WARNING: Your workspace is not extending any other
result space, but it is set to use a `linked` devel
space layout. This requires the `catkin` CMake package
in your source space in order to be built.

[build] Found '110' packages in 0.0 seconds.                                                
Starting  >>> catkin                                                                        
Finished  <<< catkin                              [ 2.4 seconds ]                           
Starting  >>> genmsg                                                                        
Starting  >>> cpp_common                                                                    
Finished  <<< genmsg                              [ 2.2 seconds ]                           
Starting  >>> gencpp                                                                        
Starting  >>> geneus                                                                        
Starting  >>> genlisp                                                                       
Finished  <<< cpp_common                          [ 1.3 seconds ]                           
Starting  >>> gennodejs                                                                     
Finished  <<< geneus                              [ 3.6 seconds ]                           
Starting  >>> genpy                                                                         
Finished  <<< genlisp                             [ 3.5 seconds ]                           
Starting  >>> rostime                                                                       
Finished  <<< gencpp                              [ 3.5 seconds ]                           
Finished  <<< gennodejs                           [ 3.5 seconds ]                           
Finished  <<< genpy                               [ 3.6 seconds ]                           
Starting  >>> message_generation                                                            
Finished  <<< rostime                             [ 1.5 seconds ]                           
Starting  >>> roscpp_traits                                                                 
Finished  <<< message_generation                  [ 1.1 seconds ]                           
Finished  <<< roscpp_traits                       [ 1.1 seconds ]                           
Starting  >>> roscpp_serialization                                                          
Finished  <<< roscpp_serialization                [ 1.4 seconds ]                           
Starting  >>> message_runtime                                                               
Finished  <<< message_runtime                     [ 1.0 seconds ]                           
Starting  >>> std_msgs                                                                      
Errors     << std_msgs:cmake /home/pi/catkin_ws/logs/std_msgs/build.cmake.005.log           
/home/pi/catkin_ws/install/share/genmsg/cmake/pkg-genmsg.cmake.em:56: error: <class 'ModuleNotFoundError'>: No module named 'genmsg'
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/", line 3302, in <module>
    if __name__ == '__main__': main()
  File "/usr/lib/python3/dist-packages/", line 3300, in main
  File "/usr/lib/python3/dist-packages/", line 3283, in invoke
    interpreter.wrap(interpreter.file, (file, name))
  File "/usr/lib/python3/dist-packages/", line 2295, in wrap
  File "/usr/lib/python3/dist-packages/", line 2284, in wrap
  File "/usr/lib/python3/dist-packages/", line 2359, in file, done, locals)
  File "/usr/lib/python3/dist-packages/", line 2401, in safe
    self.parse(scanner, locals)
  File "/usr/lib/python3/dist-packages/", line 2421, in parse, locals)
  File "/usr/lib/python3/dist-packages/", line 1425, in run
    interpreter.execute(self.code, locals)
  File "/usr/lib/python3/dist-packages/", line 2595, in execute
    _exec(statements, self.globals, locals ...
edit retag flag offensive close merge delete


Hi @ticotico I think you are right to install from source since you want to keep Octopi image. What instructions are you following?

This is the installation from source wiki:

osilva gravatar image osilva  ( 2022-02-09 19:11:21 -0500 )edit

For the error it’s likely a conflict ROS and your Python3 installation for gensmsg


osilva gravatar image osilva  ( 2022-02-09 19:15:22 -0500 )edit


export PYTHONPATH=/opt/ros/noetic/lib/python3/dist-packages/

Then restart building

osilva gravatar image osilva  ( 2022-02-09 19:19:41 -0500 )edit

Thx for the quick reply!

  • Yes, I followed the wiki (but using catkin tools)
  • Just to clarify: the /opt/ros/... only gets created when installing with the binaries, right? When installing from source, the /opt/ros/ does not exist as everything gets installed in the catkin_ws folder, right?
    • I also think it is probably some weird python2 vs python3 issue...

PS: When using catkin_make_isolated everything builds with python2, which is not what I want :/

ticotico gravatar image ticotico  ( 2022-02-10 01:43:36 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2022-02-10 05:34:46 -0500

ticotico gravatar image

Ok, found the important bit here: I had to explicitly tell catkin build to use python version 3.7, i.e.:


Hope that helps someone in the future!

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2022-02-09 13:58:26 -0500

Seen: 716 times

Last updated: Feb 10 '22