Search code examples
python-3.xcx-freezepyqt5

Executable created using cx_freeze in Windows 7 crashes with errors about PyQt5 when run on other computers


The executable runs perfectly on the system where I built it, but crashes with the following errors on the other systems I've tried...

Traceback(most recent call last):
File "C:\Python34\lib\site-packages\cx_freeze-4.3.3-py3.4-win32.egg\cx_freeze\initscripts\Console.py", line 27, in <module>
File "monitor edi.py", line 1, in <module>
File "C:\Python34\lib\importlib\_bootstrap.py", line 2214, in find and load
File "C:\Python34\lib\importlib\_bootstrap.py", line 2203, in find and load_unlocked
File "C:\Python34\lib\importlib\_bootstrap.py", line ll91, in load unlocked
File "C:\Python34\lib\importlib\_bootstrap. py", line l l 6 l , in _load_backward_compatible
File "C:\Apps\cars\Code\cars utils.py", line 7, in <module>
File "C:\Python34\lib\importlib\_bootstrap.py", line 2261, in handle fromlist
File "C:\Python34\lib\importlib\_bootstrap.py", line 321, in call with frames_removed
File "C:\Python34\lib\importlib\_bootstrap.py", line 2214, in find and load
File "C:\Python34\lib\importlib\_bootstrap.py", line 2203, in find and load_unlocked
File "C:\Python34\lib\importlib\_bootstrap.py", line ll91, in load unlocked
File "C:\Python34\lib\importlib\_bootstrap.py", line ll61, in load_backward_compatible
File "ExtensionLoader_PyQt5_QtCore.py", line 22, in <module>
File "ExtensionLoader_PyQt5_QtCore.py", line 14, in  __bootstrap__
ImportError: DLL load failed: The specified module could not be found.

I've read about some of the missing DLL issues like QWindows.DLL and libEGL.dll however it looks like cx_Freeze-4.3.3 has fixed those problems as those dlls are included in the build folder.

Built in 32 bit Python 3.4, with PyQt 5.3 and cx_Freeze 4.3.3

Here's the list of files in the build folder

icudt49.dll
icuin49.dll
icuuc49.dll
libEGL.dll
libGLESv2.dll
library.zip
monitor_edi.exe
msvcr100.dll
pyexpat.pyd
pyodbc.pyd
PyQt5.QtCore.pyd
PyQt5.QtGui.pyd
PyQt5.QtWidgets.pyd
python34.dll
pywintypes34.dll
Qt5Core.dll
Qt5Gui.dll
Qt5Widgets.dll
qwindows.dll
select.pyd
sip.pyd
tcl86t.dll
tk86t.dll
unicodedata.pyd
win32api.pyd
win32crypt.pyd
_bz2.pyd
_ctypes.pyd
_decimal.pyd
_hashlib.pyd
_lzma.pyd
_socket.pyd
_ssl.pyd
_tkinter.pyd

Any thoughts/suggestions/questions?


Solution

  • You'll need to make sure that cx_Freeze is including the atexit module. I'm not really clear on why this is, but the cx_Freeze PyQt example includes this. If you're using the cxfreeze script you can make sure this happens with the --include=atexit option. If you're invoking cx_Freeze from your own setup.py script it might look something like this code adapted from my own work in progress:

    import sys
    from cx_Freeze import setup, Executable
    
    base = None
    if sys.platform == 'win32':
        base = 'Win32GUI'
    
    setup(name = 'spamandeggs',
          version = '0.0.1',
          executables = [Executable('spamandeggs.pyw', base=base)],
          options = {'build_exe': {'includes': ['atexit']}})
    

    If you're using the PyQt5.Qsci plugin, by the way, you'll also need to explicitly include PyQt5.QtPrintSupport. And I have found that I do still need to copy libEGL.dll in after cx_Freeze has done its stuff, but I'm also using cx_Freeze 4.3.3 so I'm not sure why that is.