Compile and run a Python file

If you simply want to compile a file or group of python files from the terminal, the py_compile module can run as a script as follows:

python -m py_compile

Actually, to run a python file, you do not have to compile it. Python is an interpreted language, and you can run scripts directly from the terminal:


But you can also make the executable file by adding the #!/usr/bin/env python directive to the beginning of the file and launching the command from the terminal:

chmod +x

Once this is done the file is executable and to execute it just type:


Leave a Comment

Your email address will not be published. Required fields are marked *