Ubuntu 10.10 ‘Command not found’ for python script

pythonshellUbuntu

I have a python script 'monty.py' with

#!/usr/bin/env python

in the first line. When I run monty.py in the terminal, I get

monty.py: command not found

I am in the correct directory, and I also have chmod'ed it to be executable. Why won't this run? I am running Ubuntu 10.10 in vmware player.

Edit: Also, when I run /usr/bin/env python from the command line, the python interpreter starts up. So it is in the right place.

Edit edit: I figured it out. Apparently I don't know how to use chmod.

Best Answer

python /path/to/monty/monty.py

Or

cd /path/to/monty
./monty.py

To execute it the second way (./) the monty.py file must be marked as executable:

chmod +x /path/to/monty/monty.py
Related Question