Nenhum desses arquivos ou diretórios, mas eu posso ver!

11

Estou tentando executar um script python, em um PI Raspberry sem cabeçalho usando o winSCP e recebo a seguinte mensagem de erro:

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

Quando tento executar o terminal, obtenho:

: No such file or directory.

Eu tento um script python similar, no mesmo diretório, com o mesmo python shebang, as mesmas permissões e usando o mesmo usuário pi, e funciona.

Eu também faço um ls e consigo ver o arquivo, então não sei por que ele não será executado.

    
por reggie 10.03.2015 / 13:34

1 resposta

27

De AskUbuntu , responda por 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.

    
por 10.03.2015 / 13:49