PyInstaller; “could not find or load the Qt platform plugin ”windows"

后端 未结 4 855
轮回少年
轮回少年 2021-02-06 00:31

My PyInstaller spec:

# -*- mode: python -*-

block_cipher = None


a = Analysis([\'test.py\'],
             pathex=[\'C:\\\\Users\\\\admin\\\\compile\'],
                


        
相关标签:
4条回答
  • 2021-02-06 01:09

    There seem to be two solutions, the first one worked fine for me:

    • copy platform directory to directory of your executable. You'll find the platform directory at a location like c:\Users\<username>\envs\<environmentname>\Library\plugins\platforms or

    • Upgrade to a newer version of pyqt: conda install -c anaconda pyqt

    Use the second option with care: Do not try to use pip for pyqt installation if you have a conda environment, this might break your conda installation: https://github.com/ContinuumIO/anaconda-issues/issues/1970

    0 讨论(0)
  • 2021-02-06 01:21

    I had an issue where my python code worked fine, but the compiled .exe file would provide the "could not find or load the Qt platform plugin windows" problem. I fixed the problem by copying the ~PyQt5\Qt\plugins\platforms folder from the program's directory, generated by using pyinstaller --onedir main.py, to the folder holding the .exe file.

    It seems that in my case the only way "helping" my program detect the required .dlls was having the platforms folder next to the main.exe. Pasting the platforms folder to the program's directory after using pyinstaller --onefile main.py also makes the program work.

    0 讨论(0)
  • 2021-02-06 01:29

    This is an old question but I have been looking for a solution to this issue for days now and I finally managed to fix it WITHOUT having to manually copy the folder. Since this question also uses the .spec file I thought this would be the right place. The idea is that the .exe is looking for the .dlls in the path ./platforms/*.dll so I simply added all of the dlls to the binaries array in the spec file, where their path within the bundle is platforms/*.dll. This is because binaries is an array of tuples where the first value is the path to the file and the second one is the path within the bundle (so pretty much the path inside the .exe "container").

    Besides that, the top states mode: python which I assume means it is executed as a python script, therefore it should support variables, strings and concatenation. So my spec file ended up looking something like this:

    # -*- mode: python ; coding: utf-8 -*-
    
    block_cipher = None
    
    pf_foldr='C:\\Users\\Gabryxx7\\anaconda3\\envs\\<env_name>\\Library\\plugins\\platforms\\'
    
    a = Analysis(['C:\\Users\\Gabryxx7\\PycharmProjects\\<proj_name>\\program.py'],
                 pathex=['C:\\Users\\Gabryxx7\\PycharmProjects\\<proj_name>\\'],
                 binaries=[(pf_foldr+'qwindows.dll', 'platforms\\qwindows.dll'),
                 (pf_foldr+'qdirect2d.dll', 'platforms\\qdirect.dll'),
                 (pf_foldr+'qoffscreen.dll', 'platforms\\qoffscreen.dll'),
                 (pf_foldr+'qwebgl.dll', 'platforms\\qwebgl.dll')
                 ],
                 datas=[],
                 hiddenimports=['GUI', 'API', 'Threading', 'ssl', 'pyodbc'],
                 hookspath=[],
                 runtime_hooks=[],
                 excludes=[],
                 win_no_prefer_redirects=False,
                 win_private_assemblies=False,
                 cipher=block_cipher,
                 noarchive=False)
    pyz = PYZ(a.pure, a.zipped_data,
                 cipher=block_cipher)
    exe = EXE(pyz,
              a.scripts,
              a.binaries,
              a.zipfiles,
              a.datas,
              [],
              name='programName',
              debug=False,
              bootloader_ignore_signals=False,
              strip=False,
              upx=True,
              upx_exclude=[],
              runtime_tmpdir=None,
              console=True ) # False to avoid the console
    

    I had previously tried every solution I found online: setting up the environmental variable QT_QPA_PLATFORM_PLUGIN_PATH, reinstalling Anaconda, updating all the packages, tried with PyPi version and no venvs, but nothing worked. In the end copying the platforms folder with the dlls did the trick and so did the spec file editing to avoid the manual step.

    0 讨论(0)
  • 2021-02-06 01:31

    I just update my pyqt5 package to 5.10.1 and fix that.

    0 讨论(0)
提交回复
热议问题