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

ImportError: No module named msg

asked 2017-12-10 07:54:22 -0500

kookoo gravatar image

updated 2017-12-10 13:05:50 -0500

jayess gravatar image

I have googled a lot of solutions, but none have worked. I follow exactly the same as http://wiki.ros.org/ROS/Tutorials/CreatingMsgAndSrv#Creating_a_msg. Is there anything I missed?

my python script

import rospy
import cv2
from sensor_msgs.msg import Image
from sensor_msgs.msg import LaserScan
from face_detection.msg import TwoPoints

The error message

Traceback (most recent call last):   File "/home/tlkoo/catkin_ws/src/face_detection/src/face_detection.py", line 10, in <module>
    from face_detection.msg import TwoPoints   File "/home/tlkoo/catkin_ws/src/face_detection/src/face_detection.py", line 10, in <module>
    from face_detection.msg import TwoPoints ImportError: No module named msg

in my package.xml

  <build_depend>message_generation</build_depend>
  <build_export_depend>message_generation</build_export_depend>
  <exec_depend>message_runtime</exec_depend>


  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>rospy</build_depend>
  <build_depend>sensor_msgs</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_depend>visualization_msgs</build_depend>
  <build_depend>geometry_msgs</build_depend>

  <build_export_depend>geometry_msgs</build_export_depend>
  <build_export_depend>visualization_msgs</build_export_depend>
  <build_export_depend>roscpp</build_export_depend>
  <build_export_depend>rospy</build_export_depend>
  <build_export_depend>sensor_msgs</build_export_depend>
  <build_export_depend>std_msgs</build_export_depend>
  <exec_depend>roscpp</exec_depend>
  <exec_depend>rospy</exec_depend>
  <exec_depend>sensor_msgs</exec_depend>
  <exec_depend>std_msgs</exec_depend>

my CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)
project(face_detection)

## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  sensor_msgs
  std_msgs
  cv_bridge
  geometry_msgs
  visualization_msgs
  message_generation
#  opencv2
)

add_message_files(
   FILES
   pt.msg
   TwoPoints.msg
)

generate_messages(
   DEPENDENCIES
   sensor_msgs
   visualization_msgs std_msgs geometry_msgs
)

catkin_package(
   CATKIN_DEPENDS
   message_runtime
)

I have tried lot of "solution" found, e.g. roslib.load_manifest(), catkin_make install,

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2017-12-10 13:15:37 -0500

jayess gravatar image

The answer is telling you that you don't have a module (folder) named msg. You need to change the import statement to reflect the name of the directory that your custom messages are stored in. For example, if your package's directory structure looked like this

├── CMakeLists.txt
├── launch
│   └── face_detection.launch
├── my_messages
│   ├── TwoPoints.msg
│   └── pt.msg
├── nodes
│   └── face_detection_node
├── package.xml
├── README.md
├── setup.py
├── src
│   └── face_detection
│       └── face_detection_lib.py

As you can see, the custom messages are stored in the my_messages directory. So, your import statement would look like

from face_detection.my_messages import TwoPoints
edit flag offensive delete link more

Question Tools

Stats

Asked: 2017-12-10 07:54:22 -0500

Seen: 5,580 times

Last updated: Dec 10 '17