First of all, as @emh pointed out this is a duplicate of several other questions. One of them is stackoverflow.com/questions/2933/an-executable-python-app
There are several sets of scripts and modules that are available that allow you to convert a .py
file into an standalone executable file. Some of the more popular ones are py2exe, py2app, Pyinstaller, and Cx_freeze. The one that is best for you depends you how you are using it. First, it depends on what operating you are using. py2exe is meant specifically for creating .exe
files or windows executable files, py2app is the same as py2exe except it builds .app
files for Mac OS, pyinstaller and cx_freeze can build an executable for multiple systems, including Windows, Mac OS, and Linux. Next, what you use depends on what version of Python you have. Cx_Freeze is the only one that I mentioned that supports python 3.X; the others only support Python 2.X. The advantage pyinstaller has, is it builds all the dependent files into one executable file that unpacks right before execution, whereas the others create a folder with lots dependent files along with the executable file. I use Cx_freeze, because of its python 3.x support and relatively easy building process.
As for converting it to bytecode, there are a couple python modules for this. One is py_compile
. an example of this is:
import py_compile
py_compile.compile('filepathandname')
this will create a .pyc
file, which python will put in a folder labeled __pycache__
in the same directory as the original file.
Hope this helped.