When trying to follow a tutorial for PyQT6 (on Ubuntu 23.10) I create a virtual environment, activate it and then I install PyQT6 through pip. When that is done and I try to run a basic program that is supposed get an empty window up and running. Instead however I get an error.
When installing PyQT6 through apt and not using a virtualenv everything works, the empty window appears as expected.
Here is what I tried:
Make the virtualenv and activate it:
python -m venv venv
source venv/bin/activate
Install PyQT6:
python -m pip install pyqt6
Try out this basic part from a book and save it as myapp.py:
from PyQt6.QtWidgets import QApplication, QWidget
import sys
app = QApplication(sys.argv)
window = QWidget()
window.show()
app.exec()
Try to run it:
python myapp.py
And get the following error:
Traceback (most recent call last):
File "/home/jon/Documents/Programming/python/create_gui_applications_with_python_pyqt6/myapp.py", line 1, in <module>
from PyQt6.QtWidgets import QApplication, QWidget
ImportError: /home/jon/Documents/Programming/python/create_gui_applications_with_python_pyqt6/venv/lib/python3.11/site-packages/PyQt6/QtCore.abi3.so: undefined symbol: _ZN14QReadWriteLock16destroyRecursiveEP21QReadWriteLockPrivate, version Qt_6_PRIVATE_API
Install PyQT6 through APT instead:
sudo apt install python3-pyqt6
And now the example code works when not using a virtualenv:
python myapp.py
Expected result
However I would still like to get things running inside a virtualenv.
TL;DR
Today, installing PyQt6 with python -m pip install pyqt6
also installs PyQt6-Qt6 in v6.6.1 (released on Nov 30th). Using the previous version of PyQt6-Qt6 instead solved for me: pip install --upgrade PyQt6-Qt6==6.6.0
Long explaination
Like you, today after a fresh installation of my python package, I am no more able to run it, while it worked a week ago. It produces the same error as you:
ImportError: [...]/lib/python3.11/site-packages/PyQt6/QtCore.abi3.so: undefined symbol: _ZN14QReadWriteLock16destroyRecursiveEP21QReadWriteLockPrivate, version Qt_6_PRIVATE_API
What changed ?!
It can only come from my package dependencies. Indeed I am still on the same OS version and same Python version.
My package only frozen PyQt6==6.6.0
but not its dependencies.
Looking at PyQt6==6.6.0
dependencies, it depends on PyQt6-Qt6
that released the version 6.6.1 on Nov 30th (https://pypi.org/project/PyQt6-Qt6/6.6.1).
This is a possible breaking change from my previous installation!
I tried using the previous version 6.6.0 of PyQt6-Qt6:
pip install --upgrade PyQt6-Qt6==6.6.0
And it works for me.
Adrien