Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling Python

How can I compile and run a python file (*.py extension)?

like image 500
user161004 Avatar asked Sep 16 '09 16:09

user161004


People also ask

What does compiling mean in Python?

Compilation involves translating your human understandable code to machine understandable code, or Machine Code. Machine code is the base level form of instructions that can be directly executed by the CPU. Upon successful compilation, your code generates an executable file.

Does Python need to compile?

Python does not need a compiler because it relies on an application (called an interpreter) that compiles and runs the code without storing the machine code being created in a form that you can easily access or distribute.


2 Answers

python yourfile.py

You have to have python installed first. It will automatically compile your file into a .pyc binary, and then run it for you. It will automatically recompile any time your file changes.

http://www.python.org/download/

like image 189
Paul McMillan Avatar answered Sep 22 '22 07:09

Paul McMillan


Python compiles its files to bytecode before executing them. That means you have to have a Python interpreter installed on the target machine.

If you don't want to install Python on the target machine use py2exe, py2app or something similar.

like image 42
Georg Schölly Avatar answered Sep 22 '22 07:09

Georg Schölly