Rosanswers logo

I am trying to run tutorial , WritingServiceClient(python) on Hydro. After rosrun beginner_tutorials add_two_ints_serr.py, I get the following errors :

from: can't read /var/mail/beginner_tutorials.srv /home/brent/catkin_ws/src/beginner_tutorials/scripts/add_two_ints_server.py: line 4: import: command not found /home/brent/catkin_ws/src/beginner_tutorials/scripts/add_two_ints_server.py: line 6: syntax error near unexpected token (' /home/brent/catkin_ws/src/beginner_tutorials/scripts/add_two_ints_server.py: line 6: def handle_add_two_ints(req):'

The text was copied and pasted from the tutorial text accept the line numbers.

Any help would be appreciated.

Thank you.

Originally posted by Morpheus on ROS Answers with karma: 111 on 2014-04-07

Post score: 1

Original comments

Comment by naaj on 2021-01-20:
you can find it here

#!/usr/bin/env python

from beginner_tutorials.srv import *
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__":

1 Answer 1


Rosanswers logo

Hi Morpheus, add #!/usr/bin/env python at your first line.

Originally posted by Yantian_Zha with karma: 74 on 2014-04-27

This answer was ACCEPTED on the original site

Post score: 1

Original comments

Comment by mgrallos on 2022-03-07:
Hi good day, encountered the same problem and I tried this solution but it still doesn't work. Any alternative?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.