问题
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??
回答1:
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
orUpgrade 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
回答2:
I just update my pyqt5 package to 5.10.1 and fix that.
回答3:
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.
来源:https://stackoverflow.com/questions/47468705/pyinstaller-could-not-find-or-load-the-qt-platform-plugin-windows