Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Trying to learn how to run my scripts through Ubuntu's terminal regularly. That being said I am familiar with bash, wget, and awk being called but how do I call python files to run in the terminal? I would like to learn this but I am unsure on where to research it. I have a .pyw file that references several .py files in a folder.

share|improve this question

4 Answers 4

up vote 26 down vote accepted
python <filename>.py


Make sure the first line of your file has #!/usr/bin/env python.

Make it executable - chmod +x <filename>.py.

And run it as ./<filename>.py

share|improve this answer
where does chmod +x <filename>.py go? in Terminal? in the script? (If in the script, where?) –  tofu_bacon Sep 20 at 17:30
@tofu_bacon In the terminal. –  abhshkdz Sep 20 at 17:33
I keep getting an invalid syntax error. I've doubled check waht I'm typing. Any clue what it could be? –  tofu_bacon Sep 20 at 17:39
What's the exact command you're typing? –  abhshkdz Sep 20 at 17:40
I've tried ./, python I also have #!/usr/bin/env python as the first line of the script –  tofu_bacon Sep 20 at 17:44

First run following command

chmod +x <filename>.py

Then add the path of python interpreter and put #! front of the path.

#!/usr/bin/python or #!/usr/local/bin/python

using the pathname for where the Python interpreter is installed on your platform.

If you would like the script to be independent of where the Python interpreter lives, you can use the “env” program. Almost all Unix variants support the following, assuming the python interpreter is in a directory on the user’s $PATH:

#! /usr/bin/env python
share|improve this answer
python <>

pyw should run in the same manner, I think. You can also start an interactive console with just


Also, you can avoid having to invoke python explicitly by adding a shebang at the top of the script:

#!/usr/bin/env python

... or any number of variations thereof

share|improve this answer

Just prefix the script's filename with python


share|improve this answer

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.