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

rospy Custom message; "ImportError: No module named msg"

asked 2013-11-28 11:36:28 -0600

arlenn gravatar image

updated 2013-11-28 23:44:02 -0600

felix k gravatar image

Having trouble getting python to accept a custom message. I have performed, what I believe to be, the necessary steps to package.xml and CMakelists.txt. I feel that I perform the task as outlined in the tutorials: catkin_make etc.

I am able to find my custom message:

$rosmsg package ssimsim
ssimsim/parsedDiagMsg

when attempting to invoke this custom message type, i am met with:

Traceback (most recent call last):
  File "/home/traxx/catkin_ws/src/ssimsim/scripts/nmeaparser.py", line 7, in <module>
    from ssimsim.msg import parsedDiagMsg
ImportError: No module named msg

I am calling it as follows:

import roslib; roslib.load_manifest('ssimsim')
import rospy

from std_msgs.msg import String
from ssimsim.msg import parsedDiagMsg

I have tried several permutations of the from/import, based off various ROS help topics with little success. The .msg throwing the error I am finding more than odd.

help greatly appreciated

edit retag flag offensive close merge delete

Comments

Does the output from catkin_make show that the messages from your package are built successfully?

felix k gravatar image felix k  ( 2013-11-28 23:46:11 -0600 )edit
2

With catkin you should remove the "roslib.load_manifest" line since it is not necessary anymore.

Dirk Thomas gravatar image Dirk Thomas  ( 2013-12-30 06:14:42 -0600 )edit

4 Answers

Sort by ยป oldest newest most voted
7

answered 2013-12-29 15:14:06 -0600

Pi Robot gravatar image

This sounds similar to the problem I just had and it was solved here. The cause was that the name of the my Python script that was trying to import the message was the same as the name of my package. Apparently having the same name confuses the import statement under catkin although it worked OK using rosbuild.

--patrick

edit flag offensive delete link more
4

answered 2017-07-03 06:50:19 -0600

Hridaynath gravatar image

In my case: I am using python. I face same error. I was following this tutorial link text

The problem was ROS command "catkin_make install" (the last step of generating message) was not creating the code required to be generated for custom messages, for python, cpp and lisp, which basically helps python to understand the import statement. this generated code gets generated in :

~/catkin_ws/devel/lib/python2.7/dist-packages/package-name/msg (in case of python)

The solution : The problem was, In the tutorial I followed link text

find the lines :

catkin_package( ...
CATKIN_DEPENDS message_runtime ...
...)

I uncommented this lines. I dont know why this step shows that it is uncommented. I commented it and run the last step

catkin_make install

which made the required code in --

~/catkin_ws/devel/lib/python2.7/dist-packages/package-name/msg

check if it works: open terminal (ctrl+alt+T) you should already be running

roscore

in another terminal already move to your workspace by -

cd ~/workspace-name

source it-

source devel/setup.bash

type

python

and hit enter (to open python interpreter)

now enter command -

from package-name.msg import custom_msg

eg:

from std_msgs.msg import String

if you dont see any error you are done.

edit flag offensive delete link more

Comments

I'm not sure why you ran into the issues you did, but please see Building messages, services or actions. The CATKIN_DEPENDS on message_runtime makes sense actually. So perhaps you were missing something else.

gvdhoorn gravatar image gvdhoorn  ( 2017-07-03 07:30:47 -0600 )edit
2

answered 2015-09-03 01:09:45 -0600

Dave373 gravatar image

I was having this problem AFTER I tried to implement dynamic_reconfigure.

The DR build system put an extra <package_name> folder under the <package_name>/src folder.

As I has followed the tutorials, my python node.py code was also in the src folder, which caused python to try and load from the newly created folder instead of the main folder.

To fix this: move node.py files into a <package_name>/nodes folder

edit flag offensive delete link more
1

answered 2013-12-22 11:24:17 -0600

Chengarda gravatar image

the .msg in the import statement refers to a folder which stores your messages, the directory of your message type should be in this case:

catkin_ws/src/ssimsim/msg/parsedDiagMsg.msg
edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-11-28 11:36:28 -0600

Seen: 44,320 times

Last updated: Jul 03 '17