I am setting up a python3 virtual environment for my development, so I am staying away from the package manager apt-install
$ python3 -m venv . # create my environment in my working directory
I then activated the venv and installed pyqt5
$ source bin/activate
$ pip install PyQt5
I am notified of a successful installation and PyQt5 and PyQt5-Sip shows up in my pip list
When I build a sample application I receive the error:
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/path/to/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl, xcb.
Aborted (core dumped)
I exported the environment variable for debugging
export QT_DEBUG_PLUGINS=1
I try running my application again and here is the specific error I get in the linker
QFactoryLoader::QFactoryLoader() looking at "/path/to/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so"
Found metadata in lib /path/to/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so, metadata=
{
"IID": "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.3",
"MetaData": {
"Keys": [
"xcb"
]
},
"archreq": 0,
"className": "QXcbIntegrationPlugin",
"debug": false,
"version": 331520
}
Got keys from plugin meta data ("xcb")
QFactoryLoader::QFactoryLoader() checking directory path "/usr/bin/platforms" ...
Cannot load library /path/to/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so: (libxcb-xinerama.so.0: cannot open shared object file: No such file or directory)
The important error here is
libxcb-xinerama.so.0: cannot open shared object file: No such file or directory
So I dig deeper. I decide to use the ldd command to parse the shared library dependencies.
$ ldd /path/to/venv/lib/python3.8/site-packages/PyQt5/Qt/plugins/platforms/libqxcb.so
and lo-and behold:
libxcb-xinerama.so.0 => not found
libxcb-xinerama.so.0 => not found
These shared libraries are missing from the libqxcb shared library dependencies list. I would hope pip's installation would have this included but it is not. I have not found a solution to this problem anywhere, and the small amount of sources I have found mentioned using apt-install to solve these issues. I don't want to change my system, I prefer keeping things sandboxed.
What can I do to fix this dependency?
I'm on Ubuntu 18.04.3 and encountered the same issue. Here is what I resolved this problem.
Uninstall PyQt by using pip3
And install it via apt-get
The exact same issue occurred when I installed
pyqt5
andmatplotlib
on Ubuntu 20.04, usingpipenv
(which also creates avenv
).On my system this was easily solved by installing the missing
libxcb-xinerama0
, usingapt
:I didn't find them with pip either. I think you're stuck either compiling this from source (https://xorg.freedesktop.org/archive/individual/lib/libxcb-1.14.tar.xz) and linking to it, or installing
libxcb-xinerama0
.