Steps to convert .py to .exe in Python 3.6
- Install Python 3.6.
- Install cx_Freeze, (open your command prompt and type
pip install cx_Freeze. - Install idna, (open your command prompt and type
pip install idna. - Write a
.pyprogram namedmyfirstprog.py. - Create a new python file named
setup.pyon the current directory of your script. - In the
setup.pyfile, copy the code below and save it. - With shift pressed right click on the same directory, so you are able to open a command prompt window.
- In the prompt, type
python setup.py build - If your script is error free, then there will be no problem on creating application.
- Check the newly created folder
build. It has another folder in it. Within that folder you can find your application. Run it. Make yourself happy.
See the original script in my blog.
setup.py:
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
)
EDIT:
- be sure that instead of
myfirstprog.pyyou should put your.pyextension file name as created in step 4; - you should include each
imported package in your.pyintopackageslist (ex:packages = ["idna", "os","sys"]) any name, any number, any descriptioninsetup.pyfile should not remain the same, you should change it accordingly (ex:name = "<first_ever>", version = "0.11", description = '')- the
imported packages must be installed before you start step 8.