Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 1 down vote accepted
python /path/to/monty/monty.py


cd /path/to/monty

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

chmod +x /path/to/monty/monty.py
share|improve this answer
It runs when I use python monty.py. I just don't want to type "python" every time. Also ./monty.py doesn't work, see my comment above. –  Java man Apr 13 '11 at 17:35
See my edit about chmod +x –  Andrew Lambert Apr 13 '11 at 17:37
Did that before I asked the question. –  Java man Apr 13 '11 at 17:39
Try issuing this command: which python and verify that the output matches the path you specified in monty.py (/usr/bin/env python) –  Andrew Lambert Apr 13 '11 at 17:46
which python gives me /usr/bin/python. I tried changing the first line in the file, still no dice. –  Java man Apr 13 '11 at 17:48

Did you create monty.py in a windows text editor? If so, try dos2unix monty.py

If the file has <cr><nl> endings, then the system will see #!/usr/bin/env python\r and "python\r" can't be found.

share|improve this answer
Written in gedit on ubuntu. –  Java man Apr 13 '11 at 18:24
@Java, just to check, what does head -1 monty.py | od -c show you as the line ending? –  glenn jackman Apr 13 '11 at 18:41
#!/usr/bin/python\n –  Java man Apr 13 '11 at 19:18
@Java, please update the question with the current state. I understand that ./monty.py gives "permission denied" and monty.py gives "command not found". Is that right? You might want to show us an ls -l listing of the file. –  glenn jackman Apr 13 '11 at 19:33

Unless . (the current directory) is in your path, you won't search in the current directory for the file you're running EVEN THOUGH it's in your current directory. Instead, try running ./monty.py

share|improve this answer
Stupid comment formatting. ./monty.py bash: ./monty.py: Permission denied sudo ./monty.py sudo: /.monty.py: command not found –  Java man Apr 13 '11 at 17:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.