Running Python Programs from the Terminal
Running programs from within IDLE is fine, but sometimes you want to run a Python program from a Terminal window.
Use the python or python3 command in a Terminal, followed by the filename containing the program you want to run.
Discussion
To run a Python 2 program from the command line, use a command like this:
$ python myprogram.py |
If you want to run the program using Python 3, then change the command python to python3. The Python program that you wish to run should be in a file with the extension.py.
You can run most Python programs as a normal user; however, there are some, especially those that use the GPIO port, that you need to run as super user. If this is the case for your program, prefix the command with sudo:
$ sudo python myprogram.py |
See Also
Recipe 3.21 allows you to run a Python program as a timed event.
To automatically run a program at startup, see Recipe 3.20.