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/ws_gps_manager.py
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/python37.zip', '/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/ws_gps_manager.py", line 19, in <module>
from ws_gps_manager.msg import gpsframe2
File "/home/pi/ros_ws/src/ws_gps_manager/scripts/ws_gps_manager.py", 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.xml
as described here: http://wiki.ros.org/ROS/Tutorials/CreatingMsgAndSrv (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
print(sys.version)
print(sys.path)
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)
[Originally posted](https://answers.ros.org/question/356797/module-import-problem.-(modulenotfounderror:-no-module-named-'foo.msg';-'foo'-is-not-a-package/) by graeme on ROS Answers with karma: 46 on 2020-07-09
Post score: 1