ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A
Ask Your Question

catkin package cannot find own message type (python)

asked 2013-12-29 03:51:44 -0500

Pi Robot gravatar image

updated 2013-12-29 14:23:49 -0500


I have a package called skeleton_markers that I am in the process of converting from rosbuild to catkin. The package builds fine and I remembered to do a 'source devel/setup.bash' after compiling. But when I try to run a Python node (in the same package) that imports a message type defined in my package, I get the error:

Traceback (most recent call last):
  File "/home/patrick/catkin_ws/src/skeleton_markers/nodes/", line 24, in <module>
    from skeleton_markers.msg import Skeleton
  File "/home/patrick/Dropbox/Robotics/catkin_ws/src/skeleton_markers/nodes/", line 24, in <module>
    from skeleton_markers.msg import Skeleton
ImportError: No module named msg

When I run rosmsg on the message type, I get back the correct response:

$ rosmsg show skeleton_markers/Skeleton std_msgs/Header header
  uint32 seq
  time stamp
  string frame_id
int32 user_id
string[] name
float32[] confidence
geometry_msgs/Vector3[] position
  float64 x
  float64 y
  float64 z
geometry_msgs/Quaternion[] orientation
  float64 x
  float64 y
  float64 z
  float64 w

So I'm guessing I'm missing a key ingredient that allows a Python node to import my message type. Here are my package.xml and CMakeLists.txt files. The Python node I am trying to run is

My package.xml file:

   Skeleton Markers: Publish a list of joint markers 
   for viewing in RViz.

  <maintainer <a href="mailto:email="">Patrick">email="">Patrick</a> Goebel</maintainer>
  <url type="website"></url>
  <url type=""></url>
  <author <a href="mailto:email="">Patrick">email="">Patrick</a> Goebel</author>





My CMakeLists.txt file:

cmake_minimum_required(VERSION 2.8.3)

find_package(orocos_kdl REQUIRED)
find_package(catkin REQUIRED COMPONENTS

# Find OpenNI
pkg_check_modules(OpenNI REQUIRED libopenni)

# Find Nite
          NAMES XnVNite.h
          HINTS /usr/include/nite /usr/local/include/nite)
             NAMES XnVNite_1_3_1
             HINTS /usr/lib /usr/local/lib
             PATH_SUFFIXES lib) 





add_message_files (

  DEPENDENCIES geometry_msgs std_msgs

    DEPENDS rospy roscpp visualization_msgs std_msgs geometry_msgs
    openni_camera openni_tracker tf
    CATKIN-DEPENDS message_runtime





UPDATE ... (more)

edit retag flag offensive close merge delete


Was it built successfully? Your Python message file should be in your workspace at: devel/lib/python2.7/dist-packages/skeleton_markers/msg/

joq gravatar imagejoq ( 2013-12-29 05:05:53 -0500 )edit

Yes, the package builds successfully and the msg file you refer to does exist in the correct location.

Pi Robot gravatar imagePi Robot ( 2013-12-29 05:24:06 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2013-12-29 14:31:53 -0500

lindzey gravatar image

I think your problem is that your python script is called, and python is looking for the msg module in that script. If you rename it such that it doesn't have the same name as your package, does it work?

edit flag offensive delete link more


Awesome! That was it exactly. Never would have thought of that...Many thanks!

Pi Robot gravatar imagePi Robot ( 2013-12-29 14:41:55 -0500 )edit

Had a similar issue, also solved my problem. Note that you will need clear out the old .pyc file as well, if it exists.

jpaulos gravatar imagejpaulos ( 2014-02-28 03:48:55 -0500 )edit

This solved my problem _

antonio gravatar imageantonio ( 2016-06-22 17:50:53 -0500 )edit

In my case there was another - currently unused - file with the same name within that directory. Never thought of it until reading this post.

Falko gravatar imageFalko ( 2016-12-15 08:35:59 -0500 )edit

answered 2013-12-29 08:25:30 -0500

Dirk Thomas gravatar image

You should not modify the output directories for libraries and executables - remove the following lines from your CMakeLists.txt:


When invoking catkin_package() the optional keyword argument is CATKIN_DEPENDS (not CATKIN-DEPENDS). Please consider reading for more information when to use DEPENDS and when to use CATKIN_DEPENDS.

You should also consider filling in the other optional arguments of catkin_package(). While it will not affect your package directly it does affect packages which would depend on your package.

edit flag offensive delete link more


You should update your version of `catkinize` if it generated the `CATKIN-DEPENDS` for you. This typo has been fixed 9 months ago.

Dirk Thomas gravatar imageDirk Thomas ( 2013-12-29 08:28:54 -0500 )edit

Thanks for the clarification. Unfortunately, removing those two lines and recompiling did not solve the import problem. Also, you are correct that I was using an older version of the catkinize script because the newest version crashes as reported here:

Pi Robot gravatar imagePi Robot ( 2013-12-29 12:52:44 -0500 )edit

My above comments will not address your import problem but only point out additional problems in the posted code. Please follow the previously given advice to create a "" file and use "catkin_python_setup()" for that.

Dirk Thomas gravatar imageDirk Thomas ( 2013-12-29 13:58:47 -0500 )edit

OK, I added a file as explained in the link in @joq's Update and I added the catkin_python_setup() line to my CMakeLists.txt file. Then I did a 'rm -rf devel build', 'catkin_make' and 'source devel/setup.bash' but the import error remains.

Pi Robot gravatar imagePi Robot ( 2013-12-29 14:19:08 -0500 )edit

@Dirk Thomas - just an FYI that I updated my question with my file. Not sure if I have to add something to that file specific to message files.

Pi Robot gravatar imagePi Robot ( 2013-12-29 14:27:02 -0500 )edit

answered 2013-12-29 05:08:46 -0500

joq gravatar image

updated 2013-12-29 06:00:11 -0500

I think you probably need to move your ROS package dependencies to the CATKIN-DEPENDS part of catkin_package(), like this:

    CATKIN-DEPENDS message_runtime rospy roscpp tf openni_camera 
        openni_tracker visualization_msgs std_msgs geometry_msgs

See this catkin doc for details.

UPDATE: You are right about needing a for your Python modules. Adding one might make a difference for messages, too. Give it a try.


edit flag offensive delete link more


Unfortunately, that actually breaks the build since it appears I need 'DEPENDS openni_camera openni_tracker' in there as well. If I put that back in and try your suggestion, the package now builds but I get the same import error, even after doing a 'rm -rf devel build; catkin_make; source devel/setup.bash'.

Pi Robot gravatar imagePi Robot ( 2013-12-29 05:27:06 -0500 )edit

I am somewhat confused about what is a catkin dependency and what is a system dependency. You probably need a DEPENDS for the libopenni and Nite stuff. But, I doubt that has anything to do with the Python message import problem.

joq gravatar imagejoq ( 2013-12-29 05:51:54 -0500 )edit

Agreed. I don't know why it is so hard for a package to import its own message type(s). I wonder if I need a file with some magic incantation?

Pi Robot gravatar imagePi Robot ( 2013-12-29 05:54:49 -0500 )edit

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: 2013-12-29 03:51:44 -0500

Seen: 6,417 times

Last updated: Dec 29 '13