can't import custum message in python
Hi guys! I get this mistake.
Traceback (most recent call last):
File "prova.py", line 6, in <module>
from immagine.msg import pixel_ned
ImportError: No module named immagine.msg
It seems that my code doesn't find the custum message I created. immagine is my package and pixel_ned is the name of my .msg file. If I type rosmsg show pixel_ned it exists and I have no problem using it with a c++ code. What is going on?
My listener is this:
#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
import rospy
from immagine.msg import pixel_ned
from std_msgs.msg import Float64MultiArray
def callback(data):
rospy.loginfo(rospy.get_caller_id() + "I heard %s", data.data)
def listener():
# In ROS, nodes are uniquely named. If two nodes with the same
# name are launched, the previous one is kicked off. The
# anonymous=True flag means that rospy will choose a unique
# name for our 'listener' node so that multiple listeners can
# run simultaneously.
rospy.init_node('ascolta_immagine', anonymous=True)
rospy.Subscriber("/scrivi_immagine", pixel_ned, callback)
rospy.spin()# spin() simply keeps python from exiting until this node is stopped
if __name__ == '__main__':
listener()
And this my Cmake
cmake_minimum_required(VERSION 2.8.3)
project(immagine)
## 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
std_msgs
marta_msgs
## DI QUESTI NONSONO SICURA
geometry_msgs
message_generation
sensor_msgs
auv_lib
genmsg
)
## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)
find_package(cmake_modules REQUIRED)
find_package(Eigen REQUIRED)
## Generate messages in the 'msg' folder
add_message_files(
FILES
pixel_ned.msg
# Message1.msg
# Message2.msg
)
## Generate added messages and services with any dependencies listed here
generate_messages(
DEPENDENCIES
std_msgs
marta_msgs
)
catkin_install_python(PROGRAMS scripts/prova.py
DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
###########
## Build ##
###########
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
include
${catkin_INCLUDE_DIRS}
${Eigen_INCLUDE_DIRS}
)
## Declare a C++ library
# add_library(${PROJECT_NAME}
# src/${PROJECT_NAME}/immagine.cpp
# )
add_library(immagine src/funzioni.cpp)
## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
add_executable(gestisco_dati src/gestisco_dati.cpp)
## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
add_dependencies(gestisco_dati ${catkin_EXPORTED_TARGETS})
add_dependencies(gestisco_dati immagine_gencpp)#perchè dipende da un messaggio costumizzato
## Specify libraries to link a library or executable target against
target_link_libraries(gestisco_dati immagine ${catkin_LIBRARIES})