How to fix “ImportError: unable to find Qt5Core.dll on PATH” after pyinstaller bundled the python application

后端 未结 5 929
滥情空心
滥情空心 2021-01-05 06:01

Can\'t run QT based GUI application bundled by pyinstaller, the console output shows it is due to an import error:

ImportError: unable to find

5条回答
  •  迷失自我
    2021-01-05 06:12

    As detailed in the question, when startup the bundled application in the conda console, it runs properly, all the loaded DLLs, exported by ProcessExplorer, are in the dist dir which was created by pyinstaller. So the problem is that the path, containing pyqt DLLs, is not in the system's PATH environment. Maybe this is a bug of pyinstaller. The Solution is add the program path to system PATH env manually.

    Here is the code snip i am using:

    # Fix qt import error
    # Include this file before import PyQt5 
    
    import os
    import sys
    import logging
    
    
    def _append_run_path():
        if getattr(sys, 'frozen', False):
            pathlist = []
    
            # If the application is run as a bundle, the pyInstaller bootloader
            # extends the sys module by a flag frozen=True and sets the app
            # path into variable _MEIPASS'.
            pathlist.append(sys._MEIPASS)
    
            # the application exe path
            _main_app_path = os.path.dirname(sys.executable)
            pathlist.append(_main_app_path)
    
            # append to system path enviroment
            os.environ["PATH"] += os.pathsep + os.pathsep.join(pathlist)
    
        logging.error("current PATH: %s", os.environ['PATH'])
    
    
    _append_run_path()
    
    

提交回复
热议问题