ImportError:No module named my_custom_srv_msg_pkg.srv

Hello,
I am facing this issue though i tried all possible solutions available here

Hi @meghananr21

Make sure you compiled your messages correctly. Check if you correctly adjusted the package.xml and CMakeLists.txt in you package, to include message building dependencies. Then compile and source again.

Hi ,
I tried again by checking package.xml and CMakeLists.txt . I compiled and did source again. But still I am facing the same issue. I am able to see message error2

Try deleting the build and devel folder, then recompile. If it doesnt work, pls post your package.xml and CMakeLists.txt code

Hi ,
Please find the attachment of package.xml and CMakeLists.txt code

cmake_minimum_required(VERSION 2.8.3)
project(my_custom_srv_msg_pkg)


## Here is where all the packages needed to COMPILE the messages of topics, services and actions go.
## It's only getting its paths, and not really importing them to be used in the compilation.
## It's only for further functions in CMakeLists.txt to be able to find those packages.
## In package.xml you have to state them as build
find_package(catkin REQUIRED COMPONENTS
  std_msgs
  message_generation
)

## Generate services in the 'srv' folder
## In this function will be all the action messages of this package ( in the action folder ) to be compiled.
## You can state that it gets all the actions inside the action directory: DIRECTORY action
## Or just the action messages stated explicitly: FILES my_custom_action.action
## In your case you only need to do one of two things, as you wish.
add_service_files(
  FILES
  MyCustomServiceMessage.srv
)

## Here is where the packages needed for the action messages compilation are imported.
generate_messages(
  DEPENDENCIES
  std_msgs
)

## State here all the packages that will be needed by someone that executes something from your package.
## All the packages stated here must be in the package.xml as exec_depend
catkin_package(
  CATKIN_DEPENDS rospy
)


include_directories(
  ${catkin_INCLUDE_DIRS}
)

The below is the code for Package.xml

<?xml version="1.0"?>

<package format="2">

  <name>my_custom_srv_msg_pkg</name>

  <version>0.0.0</version>

  <description>The my_custom_srv_msg_pkg package</description>

  <maintainer email="user@todo.todo">user</maintainer>

  <license>TODO</license>

  <buildtool_depend>catkin</buildtool_depend>

  <build_depend>rospy</build_depend>

  <build_depend>std_msgs</build_depend>

  <build_depend>message_generation</build_depend>

  <build_export_depend>rospy</build_export_depend>

  <exec_depend>rospy</exec_depend>

  <build_export_depend>std_msgs</build_export_depend>

  <exec_depend>std_msgs</exec_depend>

  <build_export_depend>message_runtime</build_export_depend>

  <exec_depend>message_runtime</exec_depend>

  <export>

  </export>

</package>

Hi ,
I got it fixed , I didnt source in another webshell where i was calling service.

2 Likes