pythonlinuxubuntupython-2.7ubuntu-12.04

Ubuntu Python shebang line not working


Unable to get shebang line working in Ubuntu for python script. I only get a command not found error each time.

test.py

#!/usr/bin/env python

print ('!')

Ran

:which python
/usr/bin/python

Played around with different locations for python in the shebang but no luck including what was provided by which python. Any tips on how to troubleshoot this?

Thanks


Solution

  • If you are trying to run the command as

    $ test.py
    

    the error may not have anything to do with the shebang. Rather, the directory that test.py resides in is not in your PATH. Try

    $ ./test.py
    

    to bypass PATH lookup.

    (This is in addition to making sure that the script itself is executable.)