ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Module Import Problem. (ModuleNotFoundError: No module named 'foo.msg'; 'foo' is not a package

asked 2020-07-09 20:46:56 -0500

graeme gravatar image

updated 2022-01-22 16:10:39 -0500

Evgeny gravatar image

I am trying to compile a two variable simple message. When I include the message from the python command line it works:

pi@ws:~/ros_ws $ python3
Python 3.7.3 (default, Dec 20 2019, 18:57:59) 
[GCC 8.3.0] on linux>>> from ws_gps_manager.msg import gpsframe2
>>> a=gpsframe2()
>>> a
gps_lat: 0.0
gps_long: 0.0

However when I run it from inside the ros package I get an error:

pi@ws:~/ros_ws $ /home/pi/ros_ws/src/ws_gps_manager/scripts/
3.7.3 (default, Dec 20 2019, 18:57:59) 
[GCC 8.3.0]
['/home/pi/ros_ws/src/ws_gps_manager/scripts', '/home/pi/ros_ws/devel/lib/python3/dist-packages', '/home/pi/ros_catkin_ws/install/lib/python3/dist-packages', '/home/pi/.local/lib/python3.7/site-packages', '/usr/lib/', '/usr/lib/python3.7', '/usr/lib/python3.7/lib-dynload', '/usr/local/lib/python3.7/dist-packages', '/usr/lib/python3/dist-packages']
3.7.3 (default, Dec 20 2019, 18:57:59) 
Traceback (most recent call last):
  File "/home/pi/ros_ws/src/ws_gps_manager/scripts/", line 19, in <module>
    from ws_gps_manager.msg import gpsframe2
  File "/home/pi/ros_ws/src/ws_gps_manager/scripts/", line 19, in <module>
    from ws_gps_manager.msg import gpsframe2
ModuleNotFoundError: No module named 'ws_gps_manager.msg'; 'ws_gps_manager' is not a package

I have correctly modified my CMakefile.txt and package.xmlas described here: (I also copied a working CMake and package file from a completely different project and got the same result) The rest of the code works perfectly as long as I don't use that custom msg.

catkin_make install compiles cleanly.

The pertinent part at the top of the python script is as follows:

#!/usr/bin/env python3
import sys
import rospy
from std_msgs.msg import String,Float64
from ws_gps_manager.msg import gpsframe2

The contents of the msg file is:

float64 gps_lat
float64 gps_long

Showing that the script and the command line are executing the same version of python and they have the same package path.

 /usr/bin/env python3 returns Python3.7.3

So my question: Why does the include work from the command line, but not from the rosrun or direct execution of the script using the shebang?? The paths are the same, the module is the same, the compile completes.

(I'm on melodic)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2020-07-10 12:14:10 -0500

graeme gravatar image

updated 2020-07-10 12:15:44 -0500

For anyone else running into this problem. My solution was PATH based. The module search paths were not identical.

It seems that the script is adding its own directory to the search path which contains the same folder structure that the module is searching for, but not the right contents.

The simplest solution for me is to remove that path from the search:


There is probably a better solution somewhere deeper in the ROS code, but for now I'm just glad everything is running!

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2020-07-09 20:46:56 -0500

Seen: 6,133 times

Last updated: Jul 10 '20