Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting py file to exe, Cannot find existing PyQt5 plugin directories

I'm quite new to phyton and I've just finished my first application. Now, I'm trying to compile my .py file to an .exe buy that doestn seem to work. I've looked everywhere for a solutio to my problem, but I just cant seem to find one.

When I run this command: pyinstaller gui.py

this error shows up:

4815 INFO: Loading module hooks...
4815 INFO: Loading module hook "hook-encodings.py"...
4913 INFO: Loading module hook "hook-pydoc.py"...
4913 INFO: Loading module hook "hook-PyQt5.py"...
5019 WARNING: Hidden import "PyQt5.sip" not found!
5019 INFO: Loading module hook "hook-PyQt5.QtCore.py"...
5096 WARNING: Unable to find Qt5 translations C:/qt5b/qt_1524647842210/_h_env/Library/translations\qtbase_*.qm. These translations were not packaged.
5096 INFO: Loading module hook "hook-PyQt5.QtGui.py"...
Traceback (most recent call last):
  File "c:\users\ivo\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\ivo\anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Ivo\Anaconda3\Scripts\pyinstaller.exe\__main__.py", line 9, in <module>
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 111, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 838, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 784, in build
    exec(text, spec_namespace)
  File "<string>", line 17, in <module>
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 241, in __init__
    self.__postinit__()
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
    self.assemble()
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 500, in assemble
    module_hook.post_graph()
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\building\imphook.py", line 410, in post_graph
    self._load_hook_module()
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\building\imphook.py", line 377, in _load_hook_module
    self.hook_module_name, self.hook_filename)
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\compat.py", line 736, in importlib_load_source
    return mod_loader.load_module()
  File "<frozen importlib._bootstrap_external>", line 399, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 823, in load_module
  File "<frozen importlib._bootstrap_external>", line 682, in load_module
  File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 684, in _load
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\hooks\hook-PyQt5.QtGui.py", line 11, in <module>
    hiddenimports, binaries, datas = add_qt5_dependencies(__file__)
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 514, in add_qt5_dependencies
    more_binaries = qt_plugins_binaries(plugin, namespace=namespace)
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 132, in qt_plugins_binaries
    pdir = qt_plugins_dir(namespace=namespace)
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 117, in qt_plugins_dir
    """.format(namespace, ", ".join(paths)))
Exception:
            Cannot find existing PyQt5 plugin directories
            Paths checked: C:/qt5b/qt_1524647842210/_h_env/Library/plugins

My path variable:

C:\Users\Ivo\Anaconda3;C:\Users\Ivo\Anaconda3\Library\mingw-w64\bin;C:\Users\Ivo\Anaconda3\Library\usr\bin;C:\Users\Ivo\Anaconda3\Library\bin;C:\Users\Ivo\Anaconda3\Scripts;C:\Users\Ivo\AppData\Local\Programs\Python\Python36-32\Scripts\;C:\Users\Ivo\AppData\Local\Programs\Python\Python36-32\;C:\Users\Ivo\AppData\Local\Microsoft\WindowsApps;C:\Users\Ivo\AppData\Roaming\Composer\vendor\bin;C:\Users\Ivo\AppData\Local\atom\bin;C:\scrcpy-windows-v1.0\adb.exe;D:\xampp2\php;C:\Users\Ivo\AppData\Roaming\npm;

Ive been trying to fix this for a whole day now, if anyone could help me/ point me in the right direction that would be greatly appericiated.

edit:

Also, since i've reinstalled some things to try and fix the problem. the file wont start and gives this error:

Traceback (most recent call last):
  File "C:\Users\Ivo\Documents\temp\project\gui.py", line 9, in <module>
    from PyQt5 import QtCore, QtGui, QtWidgets
ImportError: DLL load failed: The specified procedure could not be found.
like image 628
xVivio Avatar asked Dec 24 '22 04:12

xVivio


1 Answers

Conda 4.5.11, Python 3.6.4, PyInstaller 3.4

The plugin path is determined incorrectly in hooks/qt.py. Qt requires that QCoreApplication is instantiated first, before any other calls.

My qt.py hook is in ~\anaconda3\Lib\site-packages\PyInstaller\utils\hooks\qt.py.

I edited it like so:

    json_str = exec_statement("""
        import sys

        # exec_statement only captures stdout. If there are
        # errors, capture them to stdout so they can be displayed to the
        # user. Do this early, in case PyQt5 imports produce stderr
        # output.
        sys.stderr = sys.stdout

        import json
        from %s.QtCore import QLibraryInfo, QCoreApplication

        # QLibraryInfo isn't always valid until a QCoreApplication is
        # instantiated.
        app = QCoreApplication([])
        paths = [x for x in dir(QLibraryInfo) if x.endswith('Path')]
        location = {x: QLibraryInfo.location(getattr(QLibraryInfo, x))
                    for x in paths}
        try:
            version = QLibraryInfo.version().segments()
        except AttributeError:
            version = None
        print(str(json.dumps({
            'isDebugBuild': QLibraryInfo.isDebugBuild(),
            'version': version,
            'location': location,
        })))
    """ % self.namespace)

see 1.

like image 102
Aldo Avatar answered Apr 26 '23 23:04

Aldo