1
votes

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.

1
Use command: export DISPLAY=:0 in terminal stackoverflow.com/questions/64085911/… - George G

1 Answers

0
votes

I found a workaround to my own question, but this is not necessarily ideal. If the program is run from PyCharm with the aforementioned environment variables set and I have connected to the remote host using ssh -Y from a terminal, the GUI window will be displayed with no errors. If I kill the ssh connection from the terminal, I will not be able to execute the program from PyCharm.

This workaround works for me at the moment, and I wanted to post this in case anyone else stumbles upon this question in the future, but I would appreciate it if someone could help me understand why this workaround works, or how to solve this issue without having to open a separate ssh connection from a terminal.