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

No such file or directory when using rosrun?

asked 2011-06-27 09:41:29 -0500

Sam Powers gravatar image

updated 2011-06-28 03:42:25 -0500

I'm running Diamondback on Maverick Meerkat Ubuntu. Basically the problem is that when I rosrun a particular node (State_Machine.py), I just get a " ': [Errno 2] No such file or directory " error.

I can rosrun other files in the directory, so it's definitely in my package path. The permissions are set correctly (chmod +x worked). I have "#!/usr/bin/env python" at the top of my file. I ran it on a friend's computer (who also has ROS setup), and it threw the same error for him, so it wouldn't seem to be my Linux/python. Renaming it doesn't fix the problem. Commenting out the imports doesn't help. It's been "make"d many times now. All to no avail.

I can post the code if that would help, but it's rather long, and it's not even getting to the main (doesn't do a print).

Any ideas?

edit retag flag offensive close merge delete

Comments

Can you put your code on github or the like so that I can take a look at it?
mjcarroll gravatar image mjcarroll  ( 2011-06-27 12:16:56 -0500 )edit
Can you just run the node from the command line? rosrun is just a bash script which is like roscd PACKAGE && ./path_to_script Where it does some nice tab completion on executables.
tfoote gravatar image tfoote  ( 2011-06-27 17:46:40 -0500 )edit
Oh, yes, I should have mentioned that. I can do "python State_Machine.py" and it runs fine. (EDIT: Actually, I need permission to post the code, so I have to get that first.)
Sam Powers gravatar image Sam Powers  ( 2011-06-28 03:38:16 -0500 )edit
what happens when you execute: /usr/bin/env python?
dornhege gravatar image dornhege  ( 2011-06-29 11:40:23 -0500 )edit
When I run /usr/bin/env python: Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>
Sam Powers gravatar image Sam Powers  ( 2011-06-30 03:31:34 -0500 )edit
Can you put a minimal python script in the same location as the script in question. Just the #! and a printout. If that rosruns (what I'd expect) its some problem in your code.
dornhege gravatar image dornhege  ( 2011-06-30 03:35:49 -0500 )edit

Hello, this is not working for me. C++ files work without problem. Issue is only with python files. I made the file executable with chmod +x talker.py .....(I am a beginner), added the #!/usr/bin/env python in the file, and also converted from DOS to UNIX. It still does not work for me. It specifically cannot find python files. ERROR : /usr/bin/env: ‘python’: No such file or directory ...... I am using ROS Noetic, and VS Code platform.

Tatsat gravatar image Tatsat  ( 2021-04-08 07:58:23 -0500 )edit

So, the problem got solved. I ran: sudo apt-get install python-is-python3 ....I cannot figure out how it got figured out. It had something to do with installation of python 3. I installed ROS Noetic but I did not specifically installed Python 3. So maybe the problem was there..LOL. BTW thanks to this link: https://askubuntu.com/questions/94293... I found the answer

Tatsat gravatar image Tatsat  ( 2021-04-08 09:12:54 -0500 )edit

4 Answers

Sort by » oldest newest most voted
6

answered 2011-06-30 08:25:34 -0500

Sam Powers gravatar image

My coworker figured out the answer. It was a DOS text file, not a UNIX text file. Converting it fixed the problem, and it was able to be rosrun.

I have no idea why it was a DOS text file, but at least it works now.

edit flag offensive delete link more

Comments

yea this happened to me, i wrote the file in windows pyscripter and i guess the encoding was different, re-writing the file worked

Sentinal_Bias gravatar image Sentinal_Bias  ( 2013-03-11 16:01:07 -0500 )edit

To be precise, it is the line endings which create this problem. DOS/Windows '/r/n' do not work, only UNIX line endings '/n' work. Not the file encoding. You can probably change the line endings setting in your editors preferences or buffer options. If not, use another editor :)

Gullydwarf gravatar image Gullydwarf  ( 2013-09-25 00:09:14 -0500 )edit

Fantastic! Even though this thread is dated, I was able to find it and solve this issue. Kudos! Searched for two days for a solution and this tip finally enabled a driver that was written in python. http://www.cyberciti.biz/faq/howto-un...

b2256 gravatar image b2256  ( 2016-02-05 00:16:24 -0500 )edit
2

answered 2011-06-29 11:03:05 -0500

tfoote gravatar image

you need to make State_Machine.py executable.

chmod +x State_Machine.py
edit flag offensive delete link more

Comments

I did that. Everyone who's looked at my problem has too. It doesn't help.
Sam Powers gravatar image Sam Powers  ( 2011-06-30 02:54:54 -0500 )edit
0

answered 2020-05-06 03:33:34 -0500

mirchi gravatar image

updated 2020-05-06 14:35:30 -0500

jayess gravatar image

The problem are your line ending characters, There is a simple tool that can convert the two different styles for you called dos2unix.

  1. sudo apt install dos2unix

  2. dos2unix State_Machine.py

edit flag offensive delete link more
0

answered 2020-03-05 07:03:47 -0500

Aabed Solayman gravatar image

Hi, I had the same problem It took me hours to solve it! I'm new to Linux so maybe that's why. I was making the file executable by using chmod -x myfile.py instead of chmod +x myfile.py this - changes the permission of the executable file so that file isn't going to be executed as a program!

I hope this helps and Happy coding :)

edit flag offensive delete link more

Question Tools

Stats

Asked: 2011-06-27 09:41:29 -0500

Seen: 7,585 times

Last updated: May 06 '20