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:
- Install Python 3.6.
- Install cx_Freeze: Run pip install cx_Freeze in your command prompt.
- Install idna: Run pip install idna in your command prompt.
- Create a Python script named myfirstprog.py.
- Create a new Python file named setup.py in the same directory as your script.
- 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
)
- Right-click anywhere in the script directory and select "Open command window here."
- In the command prompt, type python setup.py build.
- If there are no errors, a build folder will be created.
- Navigate to the build folder and locate the myfirstprog application.
- 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!
Statement: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