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...

6 Steps 1 min read Medium

Step-by-Step Guide

  1. 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.
  2. Step 2: Make sure you are working on the platform you need your executable to run on.

  3. Step 3: Create a new Python file named setup.py in the directory of the Python program you wish to compile.

  4. Step 4: Enter the following code into your new setup.py file.

  5. Step 5: Run the following commands in your computer's terminal: cd python setup.py build

  6. 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

M

Melissa Smith

Writer and educator with a focus on practical pet care knowledge.

27 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: