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

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

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
python3 hello.py

Or I might instead use:

python3 /home/ek/source/hello.py

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

#!/usr/bin/env python3

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

./filename

For example:

cd /home/ek/source
chmod +x hello.py
./hello.py

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

Thanks very much: worked well.