Here is the list of things to try, in rough order of likelihood:
- Ensure that the shebang line has correct syntax (you've done this already,
#!/usr/bin/python).
- Make sure the shebang is the first line in the file (not even a blank line or a comment above it).
- Verify that
/usr/bin/python actually exists and works. Your Python interpreter may be installed elsewhere. Type /usr/bin/python at a prompt and make sure Python starts. Type which python if you don't know where it is installed.
- If
. is not in your PATH (it may not be), you must run your script with ./script.py because the shell does not look for commands in the current directory by default.
- Make sure the executable bit is set on your script (
+x, verify with ls -l).
- Make sure that you are using LF only line endings in your editor. Shells can be picky, and your shebang line must end with LF only and not CRLF. This is only likely to be a problem if you're using a Windows text editor, but it might be worth checking.
- Make sure that your text editor does not silently insert a UTF-8 BOM at the start of the file. Again, this is only likely if you're using Notepad on Windows.