Ask Your Question
0

cannot include custom .msg files in python code

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

david.c.liebman gravatar image

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

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 -0600

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 imageGirts L ( 2018-09-13 02:42:06 -0600 )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

Stats

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

Seen: 1,428 times

Last updated: Jan 24 '14