TheKingElessar
TheKingElessar

Reputation: 1771

"ImportError: DLL load failed while importing" while using PyInstaller

I'm trying to package a PyQt5 Python app using PyInstaller.

When I package it normally, without using UPX, it works fine. When I start using UPX, though, I start running into a lot of problems. I have to use --upx-exclude "vcruntime140.dll" to keep that file from being corrupted.

Then, I run into this problem.

Traceback (most recent call last):
  File "main.py", line 3, in <module>
ImportError: DLL load failed while importing QtWidgets: The parameter is incorrect.
[26400] Failed to execute script main

Here's the beginning of main.py:

import sys
import PyQt5
from PyQt5 import QtWidgets
from PyQt5.QtGui import QIcon

I read here (similar problem, I think) that I might be having trouble with hidden imports, so I run the PyInstaller command with --hidden-import "PyQt5", then with --hidden-import "PyQt5" --hidden-import "QtWidgets". But I keep getting the same error, DLL load failed while importing QTWidgets.

The full PyInstaller command I'm using is:

pyinstaller -n "[exe name]" -i "[icon file path].ico" --upx-dir "[path to UPX]\upx-3.96-win64" --upx-exclude "vcruntime140.dll" --hidden-import "PyQt5" --hidden-import "QtWidgets" --clean main.py

What can I do to fix this error?

Upvotes: 1

Views: 2379

Answers (1)

Andrew
Andrew

Reputation: 36

I had the exact same problem earlier this week. I fixed it by disabling UPX entirely. You could go through adding more and more of the QT DLLs to the UPX exclude list to figure out which ones specifically it's corrupting if you still want to compress some of them, but for now I'm ok with just having it disabled entirely.

I tried many things - different versions of PyQT5, different versions of other libraries, none of that had any effect.

If you have a .spec file for folder based build, be sure to disable UPX in both the exe and coll sections.

Upvotes: 2

Related Questions