Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to run a python script, on a headless Raspberry PI using winSCP and get the following error message:

Command '"./areadetect_movie_21.py"'
failed with return code 127 and error message
/usr/bin/env: python
: No such file or directory.

When I try and run from terminal, I get:

: No such file or directory.

I try a similar python script, in the same directory, with the same python shebang, the same permissions and using the same user pi, and it works.

I also do a ls and I can see the file, so I don't know why it will not run.

share|improve this question
1  
Did you edit `areadetect_movie_21.py' on Windows? If you did see this askubuntu.com/a/372691. –  Arkadiusz Drabczyk Mar 10 at 12:36
    
yes in eclipse, why? –  reggie Mar 10 at 12:37
    
I edited my comment after I have added it. See this askubuntu.com/a/372691. –  Arkadiusz Drabczyk Mar 10 at 12:38
    
yes yes yes it worked, thanks so much! can you convert your comment to an answer so i can accept it. –  reggie Mar 10 at 12:45
    
ok, I did it :) –  Arkadiusz Drabczyk Mar 10 at 12:50

1 Answer 1

up vote 11 down vote accepted

From AskUbuntu, answer by Gilles:

If you see the error “: No such file or directory” (with nothing before the colon), it means that your shebang line has a carriage return at the end, presumably because it was edited under Windows (which uses CR,LF as a line separator). The CR character causes the cursor to move back to the beginning of the line after the shell prints the beginning of the message and so you only get to see the part after CR which ends the interpreter string that's part of the error message.

Remove the CR: the shebang line needs to have a Unix line ending (linefeed only). Python itself allows CRLF line endings, so the CR characters on other lines don't hurt. Shell scripts on the other hand must be free of CR characters.

To remove the Windows line endings, you can use dos2unix:

sudo dos2unix /usr/local/bin/casperjs

or sed:

sudo sed -i -e 's/\r$//' /usr/local/bin/casperjs

If you must edit scripts under Windows, use an editor that copes with Unix line endings (i.e. something less brain-dead than Notepad) and make sure that it's configured to write Unix line endings (i.e. LF only) when editing a Unix file.

share|improve this answer
1  
I opened the file, on the pi, via ssh in notepad on my windows PC and removed the carriage return and it works :) Thanks very much. –  reggie Mar 10 at 13:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.