ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Error "Import Command Not Found" while doing examples of service and client using rospy in Ubuntu 12.04.

asked 2014-08-21 07:42:55 -0500

ish45 gravatar image

updated 2014-08-21 15:01:38 -0500

gvdhoorn gravatar image

While doing the example of Service and Client from this page, I am getting an error "Import Command not Found" when trying to run the Server and the Client Nodes. I have checked the code but evrything is acoording to the tutorial. Can somebody please help? I am doing these examples using rospy.

The file is as below :

#!/usr/bin/env python

import rospy

from beginner_tutorials.srv import *

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 close merge delete


Yes. I have run catkin_make and source devel/setup.bash. Infact, I have been able to sucessfully run the publish, subscribe messages tutorial in python. So, I guess python has been set up properly.

Edit : python as suggested by one of the users has worked without any errors.

ish45 gravatar image ish45  ( 2014-08-21 10:09:50 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2014-08-21 09:48:44 -0500

gvdhoorn gravatar image

updated 2014-08-21 16:07:38 -0500

Have you remembered to do a catkin_make, then source devel/setup.bash before running the examples?

Without the proper environment setup, Python is not going to be able to find the ROS imports.


Right. Two things: please don't use answers to answer someone else's answer (:)). Use comments for that. Also: please update your original question with the contents of the file you are trying to run (please use formatting for that: indent every line with 4 spaces).

Lastly: searching for Import Command not Found shows a lot of pages recommending me to make sure I have #!/usr/bin/env python at the top of my file. Do you? The error is probably really import: command not found, right?

Edit2: I've fixed the formatting a bit.

  1. Can you confirm that your file is exactly like this?
  2. How do you exactly run your node?
  3. Have you made your file executable (ie: chmod +x
  4. What is the output if you do python (change to the actual name)
  5. Did you by any chance create the file in Windows (running Ubuntu in a VM)? If so, could you try fromdos and see if the console output changes?
edit flag offensive delete link more


Yes, I have added that line at the top of the file as you can see. But, it is still giving the error. The error is "Import: Command Not Found". Don't know what is missing.

ish45 gravatar image ish45  ( 2014-08-21 13:18:39 -0500 )edit

Are the line numbers also in your file? Those are not supposed to be there. Please make sure the question contains a direct copy/paste from the file you are trying to execute.

gvdhoorn gravatar image gvdhoorn  ( 2014-08-21 13:38:18 -0500 )edit

No. The line numbers are not there in the file.

ish45 gravatar image ish45  ( 2014-08-21 13:38:48 -0500 )edit

Thanks. python command has worked. Strangely, rosrun did not seem to be running. Thanks again.

ish45 gravatar image ish45  ( 2014-08-21 15:48:54 -0500 )edit

Could you answer all 5 questions please? The fact that python worked is just an indication that something isn't right with your file, and it is most likely the shebang line (the #!/usr/bin/env python).

gvdhoorn gravatar image gvdhoorn  ( 2014-08-21 16:06:04 -0500 )edit

1) Yes the file is exactly like this 2) rosrun [package name] [] 3) Yes I have run chmod +x 4) Yes, I have ubuntu installed on VB. fromdos does not seem to do anything. No output.

ish45 gravatar image ish45  ( 2014-08-21 16:30:51 -0500 )edit

But did you use a windows editor to create the file (via a shared folder fi)? fromdos is not supposed to give any output. It converts line-endings from DOS/Windows files into Unix line-endings. Could you now (after having done fromdos try just doing ./ now, or even rosrun pkg

gvdhoorn gravatar image gvdhoorn  ( 2014-08-21 16:42:42 -0500 )edit

Question Tools

1 follower


Asked: 2014-08-21 07:42:55 -0500

Seen: 10,650 times

Last updated: Aug 21 '14