Ask Your Question

ImportError: No module named my_tutorials.srv [closed]

asked 2019-10-22 15:26:59 -0600

anirban gravatar image

updated 2019-10-22 19:32:16 -0600


I am trying to learn ROS service and client feature following the tutorial here and here. After following the instructions given in those tutorials, I did catkin_make and then source devel/setup.bash and no error message were thrown. To check if the service is in ROS workspace I also performed rossrv show AddTwoInts.srv and found the following,

int64 a
int64 b
int64 sum

int64 a
int64 b
int64 sum

But after that when I run the server node by doing rosrun my_tutorials, I get the following error ImportError: No module named my_tutorials.srv. I am not able to figure out the reason of getting this error. Any help to solve the problem is appreciated. For your reference, the catkin workspace can be found here.


The is below.

#!/usr/bin/env python
from my_tutorials.srv import AddTwoInts,AddTwoIntsResponse
import rospy

def handle_add_two_ints(req):
  print "Returning [%s + %s = %s]"%(req.a, req.b, (req.a + req.b))
  return AddTwoIntsResponse(req.a + req.b)

def add_two_ints_server():
  s = rospy.Service('add_two_ints', AddTwoInts, handle_add_two_ints)
  print "Ready to add two ints."

if __name__ == "__main__":
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by stevemacenski
close date 2019-10-22 20:13:37.155744



Please provide your file, your CMakelists. As a side note, for python compiling isn't really going to do much so you really wont ever see errors.

stevemacenski gravatar imagestevemacenski ( 2019-10-22 18:50:52 -0600 )edit

Hi you can find my ros workspace here. Let me know if you need more information.

anirban gravatar imageanirban ( 2019-10-22 19:13:29 -0600 )edit

@anirban can you please put them directly into your question. This way the question is self-contained and won't go stale in the future

jayess gravatar imagejayess ( 2019-10-22 19:17:41 -0600 )edit

Your CMakelists is nearly entirely commented out -- you need to fill out the message definitions and macros at bare minimum.

stevemacenski gravatar imagestevemacenski ( 2019-10-22 19:23:19 -0600 )edit

@jayess I have updated the question with the service node.

anirban gravatar imageanirban ( 2019-10-22 19:24:02 -0600 )edit

@stevemacenski I just have updated the CmakeLists.txt file inside the package. Please let me know if you need more information.

anirban gravatar imageanirban ( 2019-10-22 19:29:28 -0600 )edit

I'm not going to be compiling this myself to debug for you, try some stuff out, I think you're learning and the best way to learn is by doing :)

stevemacenski gravatar imagestevemacenski ( 2019-10-22 19:33:23 -0600 )edit

@stevemacenski I can compile my code. I uploaded the code to get some feedback from those who had this problem before and can point me towards fixing it :)

anirban gravatar imageanirban ( 2019-10-22 19:40:09 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-10-22 20:08:55 -0600

anirban gravatar image

updated 2019-10-22 20:09:35 -0600

@stevemacenski I found that catkin_make install fixed my problem. Previously I was just doing catkin_make. Thank you.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2019-10-22 15:26:59 -0600

Seen: 24 times

Last updated: Oct 22