ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Cannot import custom service

asked 2014-06-12 11:56:02 -0500

Robocop87 gravatar image

Hi everyone!

I made a custom service following this tutorial:

I edited the CMakeLists.txt and package.xml files as instructed.

I can see my service when I run rossrv list, but the .py file does not appear in devel/lib/python2.7/dist-packages/my_package/srv. The full path exists, but the srv directory is empty.

When I try and import the service in my python file using

from my_package.srv import my_service

I get the error:

ImportError: No module named srv

Here is my CMakeLists.txt file for your review:

cmake_minimum_required(VERSION 2.8.3)

find_package(catkin REQUIRED COMPONENTS


   geometry_msgs   nav_msgs   std_msgs  

  CATKIN_DEPENDS geometry_msgs nav_msgs roscpp rospy std_msgs message_runtime


Any help?

Ubuntu 12.04 ROS Hydro

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2014-06-12 12:53:37 -0500

Robocop87 gravatar image

I believe the problem was the executable python file and included class were the same name as the package, so instead of trying to import from the package's srv directory it was trying to find a module within my defined class named srv, which it could not find.

Moral of the story, don't create python classes within .py files which are the same name as the ros package.

"rosrun name" where "" contains a class called "name" is a no-no

edit flag offensive delete link more



in my case just renaming the python file works well!

akab gravatar image akab  ( 2016-03-26 14:00:16 -0500 )edit

Thank you so much for this post! I spent 2h of trying to figure out what am I doing wrong.

mudrole1 gravatar image mudrole1  ( 2016-04-19 20:36:25 -0500 )edit

answered 2014-06-12 12:37:37 -0500

tfoote gravatar image

DId you run the build before trying to use the messages? If so what was the console output of your build?

edit flag offensive delete link more


Are you asking for the entire output of catkin_make?

Robocop87 gravatar image Robocop87  ( 2014-06-12 12:40:28 -0500 )edit

There is a line that says "Generating Python code from SRV my_package/my_service"

Robocop87 gravatar image Robocop87  ( 2014-06-12 12:41:31 -0500 )edit

Yes. In general the more information you give the easier it is for us to help you. The more context and setup you provide the more info we have.

tfoote gravatar image tfoote  ( 2014-06-12 12:58:12 -0500 )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


Asked: 2014-06-12 11:56:02 -0500

Seen: 5,245 times

Last updated: Jun 12 '14