Possible Duplicate:
Calling a python script from command line without typing “python” first
I've tried
bash$ chmod +x script.py
doesn't work. I also remember to put
#!usr/bin/env python
at the beginning of the script.
bash$ ./script.py
Does nothing, it just changes my cursor to a cross lol
UPDATE: I've fixed
#!/usr/bin/python
i've also tried
chmod a+x script.py
still nothing. My script has import commands and uses sys.argv...I've followed the instruction on this link (look at the end of the page). Nothing works
2 Answers 2
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/pythonactually exists and works. Your Python interpreter may be installed elsewhere. Type/usr/bin/pythonat a prompt and make sure Python starts. Typewhich pythonif you don't know where it is installed. - If
.is not in yourPATH(it may not be), you must run your script with./script.pybecause 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 withls -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.
Comments
the "shebang" needs to contain the full path to the executable. You're calling env, which is good, but you haven't given it the full path: start your script like so:
#!/usr/bin/env python
# ^
import, which takes a screenshot. You may now have a PNG file lying around namedsys,os, or something similar...chmodbehaves almost as though you useda, though it's filtered by your umask.