0

I have a python code which works perfectly and i want to make it more user friendly to run, so i copied the code in a new file called codee.command , wrote #!/usr/local/bin/python3 at the beginning and used chmod 770 codee.command. Then i tried double clicking on the file but it returned the following error:

/Users/serax/Desktop/Code/digits_exec.command ; exit;
zsh: /Users/serax/Desktop/Code/digits_exec.command: bad interpreter: /usr/bin/python3^M: no such file or directory
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed

I have worked on this code on vscode and I used python 3.9.6 which is installed in /usr/local/bin/. I also tried with #!/usr/bin/python3 (which contains python 3.8.2, that is not the interpreter i want) but it gives the same error.

I now tried with #!/usr/local/bin python3 and it says permission denied.

Apparently my question is a duplicate of

Are shell scripts sensitive to encoding and line endings?

serax
  • 218
  • 2
  • 11
  • That should be `#!/usr/local/bin/python3` with a slash, not a space. – tripleee Aug 31 '21 at 11:45
  • 1
    Duplicate of [Are shell scripts sensitive to encoding and line endings?](https://stackoverflow.com/questions/39527571/are-shell-scripts-sensitive-to-encoding-and-line-endings) – tripleee Aug 31 '21 at 11:46
  • 1
    Does this answer your question? [Are shell scripts sensitive to encoding and line endings?](https://stackoverflow.com/questions/39527571/are-shell-scripts-sensitive-to-encoding-and-line-endings) – karel Aug 31 '21 at 12:01
  • @serax : The error message says it pretty clear: Your #! has a carriage return character at the end. – user1934428 Aug 31 '21 at 13:12

1 Answers1

1

You've got a line ending problem. There's a carriage return ^M in digits_exec.command it seems. Remove it in a suitable editor or run dos2unix on the file.

Jens
  • 69,818
  • 15
  • 125
  • 179