5

When running PyQGIS testing 2.99 the following coredumps:

from qgis.core import *
QgsApplication.setPrefixPath("/usr", False)
qgs = QgsApplication([], False)
qgs.initQgis()

How to start migrating PyQGIS scripts to the upcoming QGIS 3?

1 Answer 1

7

See http://doc.qt.io/qt-5/embedded-linux.html :

Since the Qt 5.0 release, Qt no longer contains its own window system (QWS) implementation.

One solution (apart from e.g. setting the DISPLAY environment variable to some X-over-ssh value) is:

export  QT_QPA_PLATFORM=offscreen

The programmatical way in Python is:

import os
from qgis.core import *
os.environ["QT_QPA_PLATFORM"] = "offscreen"
QgsApplication.setPrefixPath("/usr", False)
qgs = QgsApplication([], False)
qgs.initQgis()
1
  • Just tried this on a clean install of QGIS 3.0 (Python 3.6 and PyQt5), and it failed at QgsApplication.setPrefixPath line. Strangely, it runs no problem in the QGIS python console. I've setup all of the necessary environment variables on my Windows 7. Commented Jun 7, 2018 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.