Home > Backend Development > Python Tutorial > How to Create a Standalone .exe from a Python 3.6 Script Using cx_Freeze?

How to Create a Standalone .exe from a Python 3.6 Script Using cx_Freeze?

DDD
Release: 2024-12-19 17:36:14
Original
166 people have browsed it

How to Create a Standalone .exe from a Python 3.6 Script Using cx_Freeze?

How to Convert a Python Script to Executable (.exe) in Python 3.6

Converting a Python script to an executable (.exe) allows it to run independently without the Python interpreter. Here's a solution that addresses the specific challenges you've encountered:

Method Using cx_Freeze:

Steps:

  1. Install Python 3.6.
  2. Install cx_Freeze: Run pip install cx_Freeze in your command prompt.
  3. Install idna: Run pip install idna in your command prompt.
  4. Create a Python script named myfirstprog.py.
  5. Create a new Python file named setup.py in the same directory as your script.
  6. Copy the following code into setup.py and save it:
from cx_Freeze import setup, Executable

base = None    

executables = [Executable("myfirstprog.py", base=base)]

packages = ["idna"]
options = {
    'build_exe': {    
        'packages':packages,
    },    
}

setup(
    name = "<any name>",
    options = options,
    version = "<any number>",
    description = '<any description>',
    executables = executables
)
Copy after login
  1. Right-click anywhere in the script directory and select "Open command window here."
  2. In the command prompt, type python setup.py build.
  3. If there are no errors, a build folder will be created.
  4. Navigate to the build folder and locate the myfirstprog application.
  5. Run the application to verify its functionality.

Please note:

  • Replace myfirstprog.py with the actual filename of your Python script.
  • Include any necessary imported packages in the packages list in setup.py.
  • Customize the setup information (name, version, description) in setup.py.
  • Ensure that the imported packages are installed prior to building the executable.

The above is the detailed content of How to Create a Standalone .exe from a Python 3.6 Script Using cx_Freeze?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template