How do I convert a Python program to a runnable .exe Windows program?

Question:

I am looking for a way to convert a Python Program to a .exe file WITHOUT using py2exe. py2exe says it requires Python 2.6, which is outdated. Is there a way this is possible so I can distribute my Python program without the end-user having to install Python?

Asked By: bolharr2250

||

Answers:

I’ve used cx-freeze with good results in Python 3.2

Answered By: Daniel Haley

some people talk very well about PyInstaller

http://www.pyinstaller.org/

Answered By: Tiago Peczenyj

I’ve used py2exe in the past and have been very happy with it. I didn’t particularly enjoy using cx-freeze as much, though

Answered By: inspectorG4dget

py2exe works with Python 2.7 (as well as other versions). You just need the MSVCR90.dll

http://www.py2exe.org/index.cgi/Tutorial

Answered By: Andy

Understand that every ‘freezing’ application for Python will not really secure your code in any way. Every packaging system for a stand-alone executable Python ‘program’ will include a lot of the Python libraries and interpreter, which will make your program pretty large.

That said, PyInstaller has done a nearly flawless job with everything I’ve thrown at it. Currently it only supports up to Python 2.7 but Pyinstaller’s support for a varied set of libraries large and small is unmatched in other ‘freeze’ type programs for Python.

Answered By: PenguinCoder

For this you have two choices:

  • A downgrade to python 2.6. This is generally undesirable because it is backtracking and may nullify a small portion of your scripts
  • Your second option is to use some form of exe converter. I recommend pyinstaller as it seems to have the best results.

I use cx_Freeze. Works with Python 2 and 3, and I have tested it to work on Windows, Mac, and Linux.

cx_Freeze: http://cx-freeze.sourceforge.net/

Answered By: Omega Goggles

If it is a simple py script
refer here

Else for GUI :

$ pip3 install cx_Freeze

1) Create a setup.py file and put in the same directory as of the .py file you want to convert.

2)Copy paste the following lines in the setup.py and do change the “filename.py” into the filename you specified.

from cx_Freeze import setup, Executable
setup(
    name="GUI PROGRAM",
    version="0.1",
    description="MyEXE",
    executables=[Executable("filename.py", base="Win32GUI")],
    )

3) Run the setup.py “$python setup.py build”

4)A new directory will be there there called “build”. Inside it you will get your .exe file to be ready to launced directly.
(Make sure you copy paste the images files and other external files into the build directory)

Answered By: moovon

There is another way to convert Python scripts to .exe files. You can compile Python programs into C++ programs, which can be natively compiled just like any other C++ program.

Answered By: Anderson Green
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.