I developed a simple GUI using PyQt5, which I would like to run on a remote server from PyCharm using the remote host deployment tools. The source code for a simple GUI to display a blank window is provided below.
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_())
If I ssh into this host from a terminal using X11 forwarding (-Y) and run the GUI (python3 myapp.py), the program works fine and a blank window appears as expected. However, if I run the program from PyCharm (using the same Python interpreter on the remote host), I receive the following error:
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.
Within PyCharm, I am running the script on the remote host using the same Python interpreter tested in the successful demonstration mentioned above in the terminal using ssh -Y. I also set the environment variables in PyCharm in Settings>Build,Execution,Deployment>Console>Python Console>Environment Variables. I ensured that the DISPLAY environment variable matches the DISPLAY variable when I ssh into the remote host (localhost:10.0). I tried changing the platform plugin to one of the others recommended (setting the qt_qpa_platform environment variable), and although some platform plugins do not produce the above error, the expected window does not appear.
I have seen similar posts with this error, however I don't think that the typical recommended solutions of reinstalling pyqt or moving library paths applies to this situation because the program can run outside of PyCharm. I assume that there must be an issue with the PyCharm run configuration environment variables, but I believe that I am setting everything correctly:
DISPLAY=localhost:10.0
PYTHONUNBUFFERED=1
QT_DIR=/usr/lib64/qt-3.3
QTINC=/usr/lib64/qt-3.3/include
QTLIB=/usr/lib64/qt-3.3/lib
Thanks in advance for any guidance.