1

I want to develop a PyQGIS standalone script only using Ubuntu terminal, so to start I use:

from qgis.core import *
QgsApplication.setPrefixPath("/path/to/qgis/installation", True)
qgs = QgsApplication([], False)
qgs.initQgis()
qgs.exitQgis()

But it gives me the next error:

qt.qpa.screen: QXcbConnection: Could not connect to display
Could not connect to any X display.

I understand that the error is due cause I'm not using a graphic device (I'm working through Ubuntu's terminal and I can't use a graphic device), but the second argument on QgsApplication() disables the GUI so I thought a graphic device wouldn't be necessary.

What does that error mean? Does it have any solution?

  • QgsApplication inherit from QApplication and then you need to use QCoreApplication instead of QApplication i think, chek this stackoverflow.com/questions/17979185/… – Fran Raga Apr 16 at 19:13
  • Any idea on this issue? I get the same error running app = QgsApplication([], gui_flag): QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-root' qt.qpa.screen: QXcbConnection: Could not connect to display Could not connect to any X display. – Mehran yesterday

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.