py安装程序;“无法找到或加载 Qt 平台插件“windows" [英] PyInstaller; "could not find or load the Qt platform plugin "windows"

查看:114
本文介绍了py安装程序;“无法找到或加载 Qt 平台插件“windows"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 PyInstaller 规范:

# -*- 模式:python -*-block_cipher = 无a = Analysis(['test.py'],pathex=['C:\\Users\\admin\\compile'],binaries=[('C:\\Python361\\Lib\\site-packages\\PyQt5\\Qt\\plugins\\platforms\\qwindows.dll', 'qwindows.dll')],数据=[],隐藏进口=[],钩子路径=[],runtime_hooks=[],排除=[],win_no_prefer_redirects=假,win_private_assemblies=假,密码=block_cipher)pyz = PYZ(a.pure, a.zipped_data,密码=block_cipher)exe = EXE(pyz,a. 脚本,a.二进制文件,a.zip 文件,a.数据,名称='测试',调试=假,条=假,upx=假,runtime_tmpdir=无,console=False , icon='icon.ico')

所以我遇到了一个问题,我将使用来自 pip 的最新版本的 PyInstaller 编译我的 PyQt5 5.8.2(使用 Python 3.6.1)程序,并且它可以工作!静态链接的 onefile 可执行文件在我的计算机上运行,​​上面有所有 Qt 内容.

但随后我在任何尚未设置 Qt 环境的计算机或虚拟机上对其进行了测试,并且由于无法找到或加载 Qt 平台插件‘windows’"错误而在启动时崩溃.如果您查看规范,您会注意到我尝试手动将 DLL 存储在二进制列表中,以便 PyInstaller 将其存储在可执行文件中,但这不起作用.

我想知道我需要更改什么,以便我可以编译我的应用程序,而无需执行诸如在可执行文件的文件夹中包含平台文件夹之类的操作(我希望所有内容都在可执行文件中),是吗?就像我没有意识到的规范文件中的更改一样简单,以便它将 DLL 存储在可执行文件中?

顺便说一下,这不是重复的.我查看了其他一些问题,所有这些问题要么针对不同类型的应用程序,要么解决方案是将 DLL 降级或将其存储在文件夹中,但其中任何一个我都做不到.

所以我将其更改为 onedir 只是为了查看它是否在那里,而 qwindows.dll 在文件夹内.还有一个 qt5_plugins 文件夹,其中有一个平台文件夹,其中还有一个 qwindows.dll.那么怎么检测不到dll呢??

解决方案

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

  • 将平台目录复制到可执行文件的目录中.您将在类似 c:\Users\\envs\\Library\plugins\platforms 的位置找到平台目录>

  • 升级到更新版本的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>\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

这篇关于py安装程序;“无法找到或加载 Qt 平台插件“windows"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆