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

cannot include custom .msg files in python code

asked 2014-01-23 08:05:49 -0500

david.c.liebman gravatar image

updated 2014-01-28 17:19:09 -0500

ngrennan gravatar image

I have created my own msg files and would now like to use them in python. One line trips me up over and over.

from my_package.msg import *

I get an error like this:

ImportError: No module named my_package

I do believe I have written the '.msg' files correctly, and I have executed 'catkin_make' successfully on the workspace I'm using for ros development. I also believe I've edited the CMakeLists.txt file correctly.

cmake_minimum_required(VERSION 2.8.3)
project(my_package)


find_package(catkin REQUIRED COMPONENTS
  geometry_msgs
  roscpp
  rospy
  std_msgs
  message_generation
  map_store
)

add_message_files(
  FILES
  MapListEntryList.msg
  MapListElement.msg
#   Message2.msg
)

generate_messages(
  DEPENDENCIES
  #my_package
#  MapListEntryList  
#   geometry_msgs#   std_msgs
)

catkin_package(
#  INCLUDE_DIRS include
  LIBRARIES my_package map_store
  CATKIN_DEPENDS message_runtime geometry_msgs roscpp rospy std_msgs
#  DEPENDS system_lib
)

include_directories(
  ${catkin_INCLUDE_DIRS}
)

 install(PROGRAMS
   scripts/turtlebot_listen.py
   scripts/turtlebot_map.py
   DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
 )

The two .msg files are trivial:

# MapListEntryList.msg
# num of available maps/ num of maps in list
int8 len

# list of available map_id objects
my_package/MapListElement[] list

and

# MapListElement.msg

string name
string id

I can use rosmsg to look at both messages. If anyone can point out what I'm doing wrong, I'd be grateful.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-01-24 03:55:05 -0500

david.c.liebman gravatar image

I think the answer is to source ~/catkin_ws/devel/setup.bash in your .bashrc file. Though I had run 'catkin_make' successfully I had not sourced this file and I think therefore could not reference the 'my_package' package.

edit flag offensive delete link more

Comments

Yes, I just had the same problem. Before creating the messages I had PYTHONPATH=/opt/ros/indigo/lib/python2.7/dist-packages so ~/catkin_ws/devel/lib/python2.7/dist-packages was not on the path. After creating the message files and running catkin_make, sourcing devel/setup.bash again fixed the path.

Girts L gravatar image Girts L  ( 2018-09-13 02:42:06 -0500 )edit

Hi @david.c.liebman I have the same problem but I didn't understand how to fix it. Shoul d I put source ~/catkin_ws/devel/setup.bash in my .bashrc file?

v.leto gravatar image v.leto  ( 2021-12-26 07:43:16 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2014-01-23 08:05:49 -0500

Seen: 2,840 times

Last updated: Jan 24 '14