PyQT5 not loading Qt platform plugin "xcb"

Answered

Hi -

I'm on Ubuntu 20.04, PyCharm 2022..3.2 (professional edition). Python version is anaconda 3.9.12. When I try to run a PyQt5 application inside PyCharm, I receive the error message

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.
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

A smsll application which generates this error in PyCharm is:

from PyQt5.QtWidgets import QApplication, QMainWindow

import sys
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec_()

This application runs and completes normally when run from a terminal window, outside of PyCharm, with the same version of python. I've looked around the web and could find nothing that speaks to PyCharm directly. Thanks. Kevin

2
4 comments

Do you use a local interpreter or SSH?

Have you tried reinstalling PyQt5?

0

Receiving the same error Pycharm Professional 2022.3.2. Was not receiving this error 5 days ago, and running the code from terminal works as expected.

Output without PyCharm (works normally)

pub@p-ub:~/PycharmProjects/advancedTello$ python3 cv_test.py 
Getting frames..
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.

 

 

Output with PyCharm (error):

/home/pub/PycharmProjects/advancedTello/venv/bin/python /home/pub/PycharmProjects/advancedTello/cv_test.py 
Getting frames..
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
qt.qpa.plugin: Could not find the Qt platform plugin "xcb" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.


Process finished with exit code 134 (interrupted by signal 6: SIGABRT)

 

 

 

Code:

import cv2


def get_frame():
print("Getting frames..")

cap = cv2.VideoCapture(0)

# print(freq)
while True:
ret, frame = cap.read()

cv2.imshow('frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

cap.release()
cv2.destroyAllWindows()


if __name__ == "__main__":
get_frame()
0

How did you install PyCharm?

Is the issue reproducible in a new project with a new virtualenv/conda?

0

I wish I could offer more insight but I got it to work by uninstalling/installing PyQt5 and it's various dependents (e.g.pyqtgraph, pyqtchart, pyqt5-stubs, pyqt5-sip, pyqt5-qt5, pyqt5) using different combinations of the conda package manager and the default package manager.

For the record, I was using a local interpreter. And when I switched from anaconda Python 3.10 to the system Python 3.8 inside PyCharm, the small program I submitted here worked.

I tried reinstalling PyQt5 before submitting the report here but was using only the conda package manager. Apparently, there's magic in using both package managers.

Kevin

0

Please sign in to leave a comment.