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

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.

http://wiki.ros.org/ROS/Tutorials/Wri...

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():
  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()
edit retag flag offensive close merge delete

Comments

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 filename.py 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
1

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.


Edit:

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 filename.py)?
  4. What is the output if you do python filename.py (change filename.py 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 filename.py and see if the console output changes?
edit flag offensive delete link more

Comments

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 filename.py 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 filename.py 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] [executablefile.py] 3) Yes I have run chmod +x filename.py 4) Yes, I have ubuntu installed on VB. fromdos filename.py 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 filename.py 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 filename.py) try just doing ./filename.py now, or even rosrun pkg filename.py?

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

Question Tools

1 follower

Stats

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

Seen: 10,448 times

Last updated: Aug 21 '14