How to my "exe" from PyCharm project

Anton Bondar picture Anton Bondar · Sep 28, 2013 · Viewed 109k times · Source

Writing some project on Python via PyCharm. I want to get an exe file from it. I've tried to "Save as->XXX.exe" - but ,when i'm trying to execute it there is an error "file is not supported with such kind of OS" p.s. i've got win7 x64,it doesn't work on x32 too.

Answer

Michael0x2a picture Michael0x2a · Sep 28, 2013

You cannot directly save a Python file as an exe and expect it to work -- the computer cannot automatically understand whatever code you happened to type in a text file. Instead, you need to use another program to transform your Python code into an exe.

I recommend using a program like Pyinstaller. It essentially takes the Python interpreter and bundles it with your script to turn it into a standalone exe that can be run on arbitrary computers that don't have Python installed (typically Windows computers, since Linux tends to come pre-installed with Python).

To install it, you can either download it from the linked website or use the command:

pip install pyinstaller

...from the command line. Then, for the most part, you simply navigate to the folder containing your source code via the command line and run:

pyinstaller myscript.py

You can find more information about how to use Pyinstaller and customize the build process via the documentation.


You don't necessarily have to use Pyinstaller, though. Here's a comparison of different programs that can be used to turn your Python code into an executable.