How do I run a python pgm from command line

Asked by Rory Downes

How do I run a python program, written using Idle 3, from the command line or terminal

Question information

English Edit question
Ubuntu python3-defaults Edit question
No assignee Edit question
Solved by:
Eliah Kagan
Last query:
Last reply:
Revision history for this message
Best Eliah Kagan (degeneracypressure) said :

python3 filename

Replace filename with the filename of the program. If you have not navigated (with the cd command) to the directory in which the program resides, then you'll have to either do that, or specify its absolute path (or its path relative to the current directory). For example, I might use:

cd /home/ek/source

Or I might instead use:

python3 /home/ek/source/

If your program begins with a "shebang" line, like

#!/usr/bin/env python3

and it is marked executable, then you can run it like:


For example:

cd /home/ek/source
chmod +x

Revision history for this message
Rory Downes (rorydownes54) said :

Thanks very much: worked well.