I faced this problem some times ago, after a lot of googling I found the best solution for me.
Alternatives
- Py2Exe: Which is old, the last release on PyPi is on 21 October 2014.
- pyInstaller: Is a nice tool, but with some problem that we will see later.
- auto-py-to-exe: Use pyInstaller to build the
.exe
, so suffer the same problem, but has a nice GUI and is intuitive to use.
- cx_Freeze: I think the best solution, because it was the only one that works in my case, it is also recommended from python
Investigation
During this time I looked on google and StackOverflow for the best solution, each time that I found something it was out-dated or not well explained/documented, so I studied the official docs.
py2exe
As first try I installed py2exe it seems the best option, also recommended from python, so, give it a try.
All goes fine during the installation process, so I decide to follow the tutorial and get my .exe
.
During the step 3 of the tutorial, running setup I received an error, looking on google I found this.
I gave up with py2exe.
auto-py-to-exe && pyInstaller
I have installed auto-py-to-exe and all went good, the program open without problems so I create my .exe
file, that works!
The only problem was that, the program works only on my laptop, on all the other machine where I try to execute the antivirus delete it.
Looking on google I found the github repository where I found one issue like the mine, reading it I understand that the problem is pyInstaller.
Looking on the pyInstaller repository I found one issue where one contributors tells to contact the antivirus vendo, so I gave up again.
cx_Freeze
Looking the docs it seems to be overcomplicated realize a simple .exe
, so I have studied the documentation and found what I need.
Open you project folder and create inside it a setup.py
file with inside:
from sys import executable
from cx_Freeze import setup, Executable
setup(name='programName', version='0.1', description='my fancy description')
Setting up this file require a little bit of study, there are multiple options to set. You can set the option to create a simple .exe
or also the create a windows/mac/linux installer.
Once you have your file ready, with the options that you need, just open a shell/terminal/cmd in the directory where the setup.py
file is located and execute: python setup.py build
Now in your project folder you will see a folder where inside you can find your .exe
file.