https://bugs.kde.org/show_bug.cgi?id=518249
Bug ID: 518249
Summary: Python plugins fail to load when both PyQt5 and PyQt6
are installed
Classification: Applications
Product: krita
Version First 6.0.0
Reported In:
Platform: Arch Linux
OS: Linux
Status: REPORTED
Severity: major
Priority: NOR
Component: Scripting
Assignee: [email protected]
Reporter: [email protected]
Target Milestone: ---
Steps to Reproduce:
1. Install Krita 6.0.0 (Qt6 build) on a system with both python-pyqt5 and
python-pyqt6 installed
2. Install a Python plugin (e.g. AI Image Diffusion) into
~/.local/share/krita/pykrita/
3. Launch Krita
Expected Result:
Python plugins load normally. PyQt5 is blocked from being imported to avoid Qt
version conflicts.
Actual Result:
All Python plugins fail to load. Krita prints:
Found PyQt5 in '/usr/lib/python3.14/site-packages', removing from Python's
search path to avoid crashes.
Python cannot find the Qt5 bindings.
Please make sure, that the needed packages are installed.
Root Cause:
The conflict resolution logic in /usr/lib/krita-python-libs/krita/__init__.py
(lines 14-21) is too aggressive. When it detects the wrong PyQt version, it
removes the entire parent directory (i.e. site-packages) from sys.path:
import importlib.util
pyqt_wrong = "PyQt" + ("6" if pykrita.qt_major_version() == 5 else "5")
if (spec := importlib.util.find_spec(pyqt_wrong)):
parent_folder = os.path.dirname(os.path.dirname(spec.origin))
if sys.path.__contains__(parent_folder):
print(f"Found {pyqt_wrong} in '{parent_folder}', "
"removing from Python's search path to avoid crashes.",
file=sys.stderr)
sys.path.remove(parent_folder)
On most Linux distributions, both PyQt5 and PyQt6 are installed under the same
directory (/usr/lib/pythonX.Y/site-packages/). Removing that directory from
sys.path to block PyQt5 also makes PyQt6 unfindable. The subsequent from PyQt6
import QtCore on line 25 then fails with ImportError, and the fallback from
PyQt5 import
QtCore also fails (since site-packages is gone), resulting in no Qt bindings
being available at all.
The existing code even acknowledges this risk in the comment on line 13:
"However, this will also cause any neighboring modules to be removed."
Proposed Fix:
Instead of removing site-packages from sys.path, block the wrong PyQt module by
setting its sys.modules entry to None. This is Python's standard mechanism for
preventing a module from being imported without affecting any other modules:
import importlib.util
pyqt_wrong = "PyQt" + ("6" if pykrita.qt_major_version() == 5 else "5")
if importlib.util.find_spec(pyqt_wrong):
sys.modules[pyqt_wrong] = None
print(f"Blocked {pyqt_wrong} to avoid Qt version conflicts.",
file=sys.stderr)
Setting sys.modules["PyQt5"] = None causes import PyQt5 to raise ImportError
(preventing the conflicting Qt library from being loaded), while keeping all
other packages in site-packages — including PyQt6 — fully accessible.
Environment:
- Krita 6.0.0-2 (Qt6, Arch Linux package)
- Python 3.14.3
- python-pyqt5 5.15.11-6
- python-pyqt6 6.10.2-4
- Arch Linux, kernel 6.19.9
--
You are receiving this mail because:
You are watching all bug changes.