1

I am running a PyQGIS standalone script on Ubuntu terminal in a QGIS docker:

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

But I get the following error:

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.

1

The following solution worked for me:

Xvfb :99 -ac -noreset & 
export DISPLAY=:99
instalacia xvfb:
sudo apt-get install python-pip
sudo apt-get install xvfb xserver-xephyr vnc4server
sudo pip install pyvirtualdisplay

then in the code:

gui_flag = False
app = QgsApplication([b''], gui_flag)
app.setPrefixPath('/usr')
app.initQgis()
if len(QgsProviderRegistry.instance().providerList()) == 0:
    raise RuntimeError('No data providers available.')

Your Answer

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

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