且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

安装程序;“无法找到或加载 Qt 平台插件"“windows"

更新时间:2022-10-15 15:23:14

似乎有两个解决方案,第一个对我来说很好:

  • 将平台目录复制到可执行文件的目录.您会在 c:Users<username>envs<environmentname>Librarypluginsplatforms 这样的位置找到平台目录p>

  • 升级到更新版本的pyqt:conda install -c anaconda pyqt

小心使用第二个选项:如果您有 conda 环境,请不要尝试使用 pip 进行 pyqt 安装,这可能会破坏您的 conda 安装:https://github.com/ContinuumIO/anaconda-issues/issues/1970

My PyInstaller spec:

# -*- mode: python -*-

block_cipher = None


a = Analysis(['test.py'],
             pathex=['C:\Users\admin\compile'],
             binaries=[('C:\Python361\Lib\site-packages\PyQt5\Qt\plugins\platforms\qwindows.dll', 'qwindows.dll')],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)

pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          name='test',
          debug=False,
          strip=False,
          upx=False,
          runtime_tmpdir=None,
          console=False , icon='icon.ico')

So I have ran into the problem where I will compile my PyQt5 5.8.2 (with Python 3.6.1) program with the latest version of PyInstaller from pip, and it works! The statically linked, onefile executable works on my computer with all the Qt stuff on it.

But then I test it on any computer or virtual machine that doesn't have the Qt environment set up already, and it crashes on start because of the "could not find or load the Qt platform plugin 'windows'" error. If you look at the spec you'll notice that I attempted to store the DLL in the binary list manually so PyInstaller would store it in the executable, but that didn't work.

I would like to know what I need to change so that I can compile my application without having to do something like include the platforms folder in the folder with the executable (I want everything to be in the executable), would it be as simple as a change in the spec file that I didn't realize so that it stores the DLL in the executable?

By the way, this is not a duplicate. I looked at some of the other questions and all of them were either for a different type of application or the solution was to downgrade or store the DLL in the folder and I can't do either of those.

EDIT: So I changed it to onedir just to see if it was even in there, and qwindows.dll is inside of the folder. There is also a qt5_plugins folder which has a platforms folder which also has a qwindows.dll. So how is it not detecting the dll??

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>Librarypluginsplatforms 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