21

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.

2
  • Use an external software package like cx_Freeze.
    – Matthias
    Sep 28, 2013 at 21:43
  • PyCharm does not have this feature yet, but have you tried this? py2exe.org
    – Shashank
    Sep 2, 2021 at 3:44

1 Answer 1

42

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.

4
  • 3
    So it looks like none of the python IDE's (pycharm or pydev - eclipse pluggin) have yet to incorporate the compile-to-single-executable functionality into the IDE itself. If this is not the case, please let me know. :-) Oct 26, 2016 at 16:30
  • 3
    Related: Configuring Pycharm to run Pyinstaller
    – Stevoisiak
    Apr 9, 2018 at 18:58
  • You can include "--onefile": pyinstaller myscript.py --onefile to have only one big .exe file
    – Vandre
    Sep 22, 2022 at 21:00
  • Can you convert to .EXE using PyCharm free edition, or do you need the paid version? Oct 7, 2022 at 21:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.