How to Compile Python Script
Download cx_Freeze from Sourceforge., Make sure you are working on the platform you need your executable to run on.,Create a new Python file named setup.py in the directory of the Python program you wish to compile., Enter the following code into...
Step-by-Step Guide
-
Step 1: Download cx_Freeze from Sourceforge.
It's a tool for packaging Python scripts into standalone executables. , For example, if you want to create a Windows executable file, run cx_Freeze on Windows.
Same goes for Mac and Linux.,, (As always in Python, correct indentation is important, and unfortunately is not shown here due to formatting difficulties.): import sys from cx_Freeze import setup, Executable base = None if sys.platform == 'win32': base = 'Win32GUI' executables = [ Executable(Python program name, base=base) ] setup(name=executable_name, version='version'
description='desc'
executables=executables ) ,, It should have been created during the previous step.
Open that folder and the folder inside it.
There's your executable! The other files in that directory are required to run your executable, so be sure to always keep them with the executable.
The build can be customized in many ways.
See cx-freeze.readthedocs.org for a description of all possible options. -
Step 2: Make sure you are working on the platform you need your executable to run on.
-
Step 3: Create a new Python file named setup.py in the directory of the Python program you wish to compile.
-
Step 4: Enter the following code into your new setup.py file.
-
Step 5: Run the following commands in your computer's terminal: cd python setup.py build
-
Step 6: Look for a new folder called "build" in the Python program's directory.
Detailed Guide
It's a tool for packaging Python scripts into standalone executables. , For example, if you want to create a Windows executable file, run cx_Freeze on Windows.
Same goes for Mac and Linux.,, (As always in Python, correct indentation is important, and unfortunately is not shown here due to formatting difficulties.): import sys from cx_Freeze import setup, Executable base = None if sys.platform == 'win32': base = 'Win32GUI' executables = [ Executable(Python program name, base=base) ] setup(name=executable_name, version='version'
description='desc'
executables=executables ) ,, It should have been created during the previous step.
Open that folder and the folder inside it.
There's your executable! The other files in that directory are required to run your executable, so be sure to always keep them with the executable.
The build can be customized in many ways.
See cx-freeze.readthedocs.org for a description of all possible options.
About the Author
Melissa Smith
Writer and educator with a focus on practical pet care knowledge.
Rate This Guide
How helpful was this guide? Click to rate: