Cannot import custom message after successful `catkin_make`

asked 2018-05-28 10:32:00 -0500

n1k31t4 gravatar image

updated 2018-05-28 12:00:32 -0500

I am having issues using a custom message. I have the message file in the /msg folder, I have adjusted theCMakeList.txt and so on too. However, when I run the launch file for my package that uses the custom message, it tells me that the module does not exist. ImportError: no module named my_package.msg.

I am trying to import the message into a script in the src/ directory of the package where the message itself is in the msg/ directory.

I have also been running source devel/setup.bash after every catkin_make (Perhaps that is specific to the tutorial I am working through?). Also been running rospack profile. Autocompletion works for the named package, but just this import issue that fails. But it gets more interesting...

I found that the custom message was indeed generated by catkin_make, and I found it in /home/user/catkin_ws/devel/lib/python2.7/dist-packages/my_package/msg/. However, all the files there were preceded with underscores: _MyMsg.py, __init__.py and their compiled counterparts: _MyMsg.pyc and __init__.pyc. I managed to import and use the message with the import statement just importing the entire msg module (the final folder in the path above), then I had to use the custom message from that module:

# import entire module
from my_package import msg

# create an object from my custom message type
cust_msg = msg.MyMsg()

If anyone can explain to my what I might be doing wrong, I'd love to know!

Just to mention that I didn't fall into the common trap: the name of my package and the scripts that import the custom message were not the same ;) I also tried putting __init__.py files in the relevant folders to see if not being a module itself was preventing the imports.

Any ideas what I am doing wrong?

There is a very similar question here - but as I already mentioned, I am indeed sourcing the setup.bash file

Edit:

I have tested it from another package that I made, and am able to import the custom message without any issues. So it there a problem to import a custom message from within the src/ folder of the package where the custom message is defined?

edit retag flag offensive close merge delete

Comments

Added further information and test results

n1k31t4 gravatar imagen1k31t4 ( 2018-05-28 12:00:35 -0500 )edit

Do you have message definitions stored in the msg and src directories?

jayess gravatar imagejayess ( 2018-05-28 12:55:39 -0500 )edit

No, only in the /msg directory within my_package.

n1k31t4 gravatar imagen1k31t4 ( 2018-05-29 03:01:35 -0500 )edit