I'm trying to make my .py files executable so I can run them using ./filename.py, but its not working for me.
What I did was adding the shebang #!/usr/bin python3 and used the command chmod +x filename.py. When I run ./filename.py then as normal user, I get the error message below
bash: ./filename.py: /usr/bin: bad interpreter: Permission denied
As superuser, it tells me this instead:
sudo: unable to execute ./filename.py: Permission denied
Opening the file the usual method (python3 filename.py) it works fine.
When I changed the shebang to #!/usr/bin/env python3 it tells me this:
/usr/bin/env: ‘python3\r’: No such file or directory
which python3to get the location, then#!/usr/bin/python3without spaces in the file in question... – George Udosen Mar 25 '17 at 19:46#!/usr/bin/env python3(or less portable#!/usr/bin/python3, but it is recommended to useenv) is the correct shebang. Either you have a typo in that line, or your installation is a bit messed up if there is no/usr/bin/envexecutable. Can you verify it is there usingwhich envand/or/usr/bin/env --version? – Byte Commander Mar 25 '17 at 19:47/usr/bin/env: ‘python3\r’: No such file or directory. the response for which env is/usr/bin/env. the version is 8.25. – young marx Mar 25 '17 at 20:12bash: ./camel_game.py: /usr/bin/python3^M: bad interpreter: No such file or directorywhen using#!/usr/bin/python3. the working directory is~/PycharmProjects/filename. – young marx Mar 25 '17 at 20:36vim, you can use commandset ff=unixto change the line endings from DOS style (\r\n) to Unix style (\n) - no need for an external command such asdos2unix– steeldriver Mar 25 '17 at 22:12