Search code examples
pythonpython-3.xpyinstallerpy2execx-freeze

converting .py to .exe using Python 3.5/3.6?


I created an application in Python 3.6 with a GUI built in PyQt5. Some modules are only available for Python 3.5 and 3.6. I managed to pack it on Mac using py2app. I am trying to do the same thing on Windows. I tried to use this guide, but I still have issues. For what I understand I have 3 options:

  1. py2exe
  2. pyinstaller
  3. cx_Freeze

1) py2exe

According to here py2exe is still not available for python3.6, I need to use python3.5 then.

Using 3.5, I get this error and the compilation stops:

error: [Errno 2] No such file or directory: 'C:\\Users\\carlo\\AppData\\Roaming\\Python\\Python35\\site-packages\\py2exe\\run-py3.5-win32.exe'

2) pyinstaller Running pyinstaller through Python3.5 as: pyinstaller --onefile APP.py

I get just a bunch of warnings (lib not found) but the compilation gets to the end. The created EXE, though, opens the command prompt and pops up the following error:

   Traceback (most recent call last):
  File "site-packages\PyInstaller\loader\rthooks\pyi_rth_qt5plugins.py", line 46, in <module>
  File "c:\program files (x86)\python35-32\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 573, in load_module
    module = loader.load_module(fullname)
ImportError: DLL load failed: %1 is not a valid Win32 application.
Failed to execute script pyi_rth_qt5plugins

3) cx_Freeze Using python3.5, it first give the 'TCL_LIBRARY' error. Following the instructions here the compilation goes smoothly. The created application, however, opens up and closes immediately. It simply doesn't work. Using python3.6, the compilation seems okay. When I try to open the application, this error pops up. I just managed to take a quick screen-shot:

Does anybody have any suggestion? Any alternative I am not considering?


Solution

  • I managed to solve the problem! I followed the instructions here. I first ran (with Python3.5):

    pyinstaller CodeName.py

    Then I modified the .spec file as indicated in the link and the magic happened!