0
$\begingroup$

Rosanswers logo

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


Originally posted by arlenn on ROS Answers with karma: 71 on 2013-11-28

Post score: 7


Original comments

Comment by felix k on 2013-11-29:
Does the output from catkin_make show that the messages from your package are built successfully?

Comment by Dirk Thomas on 2013-12-30:
With catkin you should remove the "roslib.load_manifest" line since it is not necessary anymore.

$\endgroup$

4 Answers 4

0
$\begingroup$

Rosanswers logo

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


Originally posted by Pi Robot with karma: 4046 on 2013-12-29

This answer was ACCEPTED on the original site

Post score: 7

$\endgroup$
0
$\begingroup$

Rosanswers logo

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

Originally posted by Chengarda with karma: 156 on 2013-12-22

This answer was NOT ACCEPTED on the original site

Post score: 1

$\endgroup$
0
$\begingroup$

Rosanswers logo

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


Originally posted by Dave373 with karma: 21 on 2015-09-03

This answer was NOT ACCEPTED on the original site

Post score: 2

$\endgroup$
0
$\begingroup$

Rosanswers logo

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.


Originally posted by Hridaynath with karma: 65 on 2017-07-03

This answer was NOT ACCEPTED on the original site

Post score: 4


Original comments

Comment by gvdhoorn on 2017-07-03:
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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.