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

ImportError: No module named node_example.msg

asked 2017-09-06 13:54:48 -0500

Younès gravatar image

updated 2017-09-07 09:57:12 -0500

I have a package named node_exemple containing an msg folder containing these files

ViewTemplate.msg To run a python file depending on this message I used :

from node example.msg  import ViewTemplate

But I get this error :

from node_example.msg import ViewTemplate   
ImportError: No module named node_example.msg

The CMakeLists.txt is here :

cmake_minimum_required(VERSION 2.8.3) 
project(node_example)

find_package(catkin REQUIRED COMPONENTS 
  dynamic_reconfigure 
  message_generation 
  roscpp 
  rosgraph_msgs 
  nav_msgs 
  rospy 
  std_msgs
)

add_message_files(FILES 
  NodeExampleData.msg 
  TopologicalAction.msg 
  TopologicalEdge.msg 
  TopologicalMap.msg 
  TopologicalNode.msg 
  ViewTemplate.msg 
)

generate_messages(DEPENDENCIES 
  geometry_msgs
  std_msgs
)

generate_dynamic_reconfigure_options(cfg/nodeExample.cfg)

catkin_package(CATKIN_DEPENDS 
  dynamic_reconfigure 
  message_runtime 
  roscpp 
  rosgraph_msgs
  rospy
  std_msgs
  visualization_msgs 
)

include_directories(include ${catkin_INCLUDE_DIRS})

install(PROGRAMS 
  src/main_lv.py
  src/pylistener.py
  src/pytalker.py
  src/ratslam/posecell_network.py
  src/ratslam/experience_map_younes.py 
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

install(PROGRAMS 
  src/main_lv.py
  src/main_em.py
  src/pytalker.py
  src/ratslam/posecell_network.py
  src/ratslam/experience_map_younes.py
  src/ratslam/local_view_match.py
 DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
edit retag flag offensive close merge delete

Comments

Can you post your CMakeLists.txt? Also, is the message in a directory called msg?

jayess gravatar image jayess  ( 2017-09-06 14:10:46 -0500 )edit

Yes I put the message in a directory called msg

Younès gravatar image Younès  ( 2017-09-07 07:24:57 -0500 )edit
1

@Younès: please update your question with new information instead of posting a new answer. I updated your question with the info from the answer that you posted (and formatted it). Please delete the answer that you posted. Thanks.

jayess gravatar image jayess  ( 2017-09-07 09:57:29 -0500 )edit
1

thank you ok

Younès gravatar image Younès  ( 2017-09-07 09:58:10 -0500 )edit

Did you run catkin_make prior to trying to run the node? You will need to do that to have the messages be generated.

Thomas D gravatar image Thomas D  ( 2017-09-07 10:02:18 -0500 )edit

@Younès: just as an aside, you should look at this tutorial on using a Makefile with Python

jayess gravatar image jayess  ( 2017-09-07 11:54:11 -0500 )edit

1 Answer

Sort by » oldest newest most voted
0

answered 2017-09-12 02:56:57 -0500

Alberto E. gravatar image

Hello,

There are quite a few things that can go wrong when creating a custom message. By the error you are showing, and assuming that you didn't forget to compile your workspace, I woud say that maybe you've missed to do the source.

source devel/setup.bash

By the way, I've created a video showing the steps you should do when you create a custom a message, by reproducing a case based on yours. The steps the video covers are:

  1. Create the package containing the Message file.
  2. Modify the CMakeLists.txt file
  3. Modify the package.xml file
  4. Compile and source your workspace
  5. Use the new message in a Python Script

Here you have the video in case you want to have a look: https://www.youtube.com/watch?v=ZPmlF...

Hope it helps!

edit flag offensive delete link more

Comments

2

There is not information here to be a complete answer. Modify the CMakeLists.txt and package.xml how? Use the new message how? Please include all of the relevant information (i.e., what to change and the script that you're referring to).

jayess gravatar image jayess  ( 2017-09-12 11:25:35 -0500 )edit

Thank you. It works.

Younès gravatar image Younès  ( 2017-09-12 13:44:59 -0500 )edit

@Younès You're welcome! Glad to help.

Alberto E. gravatar image Alberto E.  ( 2017-09-12 14:25:34 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2017-09-06 13:54:48 -0500

Seen: 3,148 times

Last updated: Sep 12 '17