Robotics StackExchange | Archived questions

ImportError: No module named my_tutorials.srv

Hi,

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,

[my_tutorials/AddTwoInts]:
int64 a
int64 b
 ---
int64 sum

[rospy_tutorials/AddTwoInts]:
int64 a
int64 b
---
int64 sum

But after that when I run the server node by doing rosrun my_tutorials add_two_ints_server.py, 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.

Update

The add_two_ints_server.py 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():
  rospy.init_node('add_two_ints_server')
  s = rospy.Service('add_two_ints', AddTwoInts, handle_add_two_ints)
  print "Ready to add two ints."
  rospy.spin()

if __name__ == "__main__":
  add_two_ints_server()

Asked by anirban on 2019-10-22 15:26:59 UTC

Comments

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

Asked by stevemacenski on 2019-10-22 18:50:52 UTC

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

Asked by anirban on 2019-10-22 19:13:29 UTC

@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

Asked by jayess on 2019-10-22 19:17:41 UTC

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

Asked by stevemacenski on 2019-10-22 19:23:19 UTC

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

Asked by anirban on 2019-10-22 19:24:02 UTC

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

Asked by anirban on 2019-10-22 19:29:28 UTC

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 :)

Asked by stevemacenski on 2019-10-22 19:33:23 UTC

@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 :)

Asked by anirban on 2019-10-22 19:40:09 UTC

Answers

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

Asked by anirban on 2019-10-22 20:08:55 UTC

Comments