How do I run a python pgm from command line

Asked by Rory Downes on 2011-04-13

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:
2011-04-13
Last query:
2011-04-13
Last reply:
2011-04-13

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

Rory Downes (rorydownes54) said : #2

Thanks very much: worked well.