Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
PyQT5 could not load the Qt platform plugin “xcb”
Gurkirat Singh last edited by
I am using the same code but with different libraries.
The code with PyQt5
import sys from PyQt5.QtWidgets import QApplication, QWidget if __name__ == '__main__': app = QApplication(sys.argv) w = QWidget() w.resize(250, 150) w.move(300, 300) w.setWindowTitle('Simple') w.show() sys.exit(app.exec_())
The code with PySide2
import sys from PySide2.QtWidgets import QApplication, QWidget if __name__ == '__main__': app = QApplication(sys.argv) w = QWidget() w.resize(250, 150) w.move(300, 300) w.setWindowTitle('Simple') w.show() sys.exit(app.exec_())
The code works fine when using
PySide2but the following error comes when using
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" 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)
PS: Trust me I have tried everything. Like reinstalling pyqt5 and qt5 framework
OS: Linux h3ll 5.3.12-1-MANJARO #1 SMP PREEMPT Thu Nov 21 10:55:53 UTC 2019 x86_64 GNU/Linux
QT Version: 5.12
Okay I ran the following in my python3, pyqt5, windows10 environment and everything works so while you may have checked everything all I can say is there is something off in your environment some how -- that and
sys.exit(app.exec_( ) )is the PyQt4 way to implement that line I have used the PyQt5 version below but I highly doubt that is your issue
from PyQt5.QtWidgets import QApplication, QWidget if __name__ == '__main__': MainEvntThrd = QApplication() Win = QWidget() Win.setWindowTitle('Simple') Win.resize(250, 150) Win.move(300, 300) Win.show() MainEvntThrd.exec()
JonB last edited by JonB
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
The first port of call for plugins is to run your application with the
QT_DEBUG_PLUGINSenvironment variable set to 1 to see what might go wrong when the plugin is loaded.
It will come down to how you have installed PyQt vs PySide2, presumably. Compare your output with that environment variable set against, say:
that and sys.exit(app.exec_( ) ) is the PyQt4 way to implement that line I have used the PyQt5 version below
Can you show where it's specified that it does not apply to PyQt5 ?
For example in the PyQt5 designer documentation, you have the classic:
import sys from PyQt5.QtWidgets import QApplication, QDialog from ui_imagedialog import Ui_ImageDialog app = QApplication(sys.argv) window = QDialog() ui = Ui_ImageDialog() ui.setupUi(window) window.show() sys.exit(app.exec_())
JonB last edited by
sys.exit(app.exec())[Python3] in PyQt5, works as expected across platforms. Not aware particularly of a change from PyQt4 to PyQt5, same behaviour.
@SGaist if you research it you will find something like this and I also eventually found it in the PyQt5 documentation but did not record the where although I can say it was not all that easy to find. So you are free to do with it what you like but its out there and it works as outlined. Hey if you can find it in the PyQt documentation post a link then we will have one to reference later on ;-)
In PyQt5, you do not need sys.exit() at all. app.exec_() or app.exec() alone is enough and it works as it should. They fixed some things in PyQt5 under the hood so that you do not need that sys.exit() anymore. However if you want your code to run on the deprecated PyQt4, then yes you have to use sys.exit() there. Also, app.exec_() and app.exec() are interchangable, so you can use whichever you like although app.exec_() is being maintained only for backwards compatibility and app.exec() is the new PyQt5 version. So if you want your code to run on the deprecated PyQt4 as well, then stick with sys.exit(app.exec_()) but if you have fully embraced PyQt5 you only need app.exec().
So how did this all come about here is a brief history. Until Python 3, exec was a reserved keyword, so the PyQt devs added underscore to it. From Python 3 onwards, exec is no longer a reserved keyword (because it is a builtin function; same situation as print), so it made sense in PyQt5 to provide a version without an underscore to be consistent with C++ docs, but keep a version with underscore for backwards compatibility. So for PyQt5 with Python 3, the two exec functions are basically the same. For older PyQt, only exec_() is available. This of course is explained in the PyQt5 documentation.
JonB last edited by JonB
If you choose not to use
app.exec()in PyQt5 as you say, could you please explain how you return a process exit code to any caller which is interested in it? Of course you have always been able to omit the
sys.exit()in either PyQt4 or PyQt5, it's just that then you cannot control the exit code. That is the reason
sys.exit()has always been used....
@JonB I believe they cover that in the documentation as I recall reading mention of that and seeing something in that regards in the stuff I read while researching it. Again I have do not recall where it is as it was a while back when I discovered it and researched it thoroughly before accepting it. So if you dig through the PyQt5 documentation I am sure you will find it. Still if you need to use the old stuff or just want to that is up to you.