My PyInstaller spec:
# -*- mode: python -*-
block_cipher = None
a = Analysis([\'test.py\'],
pathex=[\'C:\\\\Users\\\\admin\\\\compile\'],
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\\\\Library\\plugins\\platforms\\'
a = Analysis(['C:\\Users\\Gabryxx7\\PycharmProjects\\\\program.py'],
pathex=['C:\\Users\\Gabryxx7\\PycharmProjects\\\\'],
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.