Ask Your Question

Unable to import custom messages (Python)

asked 2016-05-04 17:33:24 -0500

IanCol gravatar image

Hi There,

I am following the python publisher/subscriber tutorial located here. I followed the first couple of steps to download and build the code. Then, as instructed, I started a roscore and in a new terminal I ran "rosrun node_example". That's when the following error came up:

Traceback (most recent call last):
  File "/home/icolwell/node_example/src/", line 14, in <module>
    from node_example.msg import NodeExampleData
ImportError: No module named msg

It appears that python can't find the python headers for the custom ROS message. I did a bit of investigating and these are the results:

1 The output of "rosmsg package node_example" is:


So it appears that ROS is aware that custom messages exist.

2 I also tried to ensure my $PYTHONPATH includes node_example by running "source ~/node_example/devel/setup.bash". Then the output of "echo $PYTHONPATH" was:


3 The contents of "~/node_example/devel/lib/python2.7/dist-packages/node_example/msg" is totally empty. Is this correct? I would assume that there should be something there that was built according to CMakeLists.txt but I am not familiar with python modules.

I also looked around online and other people have had similar problems. However, they seemed to be caused by a screwed up package.xml or CMakeLists.txt file. This doesn't seem to be the case here since it is unmodified tutorial code, and it appears that all the correct message generation related dependencies are there.

Does anyone have any idea what is happening here? Or at the very least is someone able to reproduce the same error? I am running Indigo on 14.04.

Any help will be greatly appreciated :D

edit retag flag offensive close merge delete



The example package has been catkin-ized since the ROS wiki tutorial was written. Try building it with catkin_make instead of the cmake . and rosmake stuff. Also, what's the output of rosmsg show NodeExampleData ?

spmaniato gravatar image spmaniato  ( 2016-05-04 18:51:17 -0500 )edit

Your point 3 indicates that there is something wrong with your build process. If custom messages from the node_example package are properly built, the Python message implementations should be in the directory you mentioned.

jarvisschultz gravatar image jarvisschultz  ( 2016-05-05 07:09:41 -0500 )edit

I went ahead and converted your comment to an answer. If the question is no longer applicable, it is best if it shows up as answered. Feel free to edit the text, and please accept your own answer. Glad the problem disappeared!

jarvisschultz gravatar image jarvisschultz  ( 2016-05-05 19:17:18 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2016-05-05 16:18:30 -0500

IanCol gravatar image

updated 2016-05-06 08:22:36 -0500

Thanks spmaniato and jarvisschultz! I erased it completely then re-cloned to my catkin workspace and it worked just fine. I swear I had tried that before but I may have just copied it instead of deleting and re-cloning.

To sum it up:

  1. I cloned the git repo into "~/catkin_ws/src"
  2. I then ran a "catkin_make" from "~/catkin_ws"
  3. The directory located at "~/catkin_ws/devel/lib/python2.7/dist-packages/node_example/msg" now contains stuff! there is a python init and a ""

Also, I can't approve my own answer since I'm a newb. Oh well.

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

1 follower


Asked: 2016-05-04 17:33:24 -0500

Seen: 4,175 times

Last updated: May 06 '16