Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 19 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

Just prefix the script's filename with python


  python python_file_name.py
share|improve this answer
python <filename.py>

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

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

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.