1

I want to run standalone python script in Docker with QGIS and Ubuntu Xenial and there is problem with GUI.

When QgsApplication is qgs = QgsApplication([],True, None) the error is cannot connect to x server. If I set QgsApplication to False qgs = QgsApplication([],False, None),the error is QPixmap: Cannot create a QPixmap when no GUI is being used.

This is my initialization of the script

#!/usr/bin/env python
#import libraries
import sys, os
import qgis
from qgis.core import *
from PyQt4.QtCore import QFileInfo

# supply path to qgis install location
QgsApplication.setPrefixPath("/usr", True)

# create a reference to the QgsApplication
qgs = QgsApplication([],True, None) #preco hadze False chybu, ked nechcem vyuzit GUI ?
#app.setPrefixPath("/usr", True)

# load providers
qgs.initQgis()

# import processing and set system path to processing
sys.path.append('/usr/share/qgis/python/plugins')   
from processing.core.Processing import Processing
Processing.initialize()
from processing.tools import *

How to initialize script to get it running ? I do not need GUI.

  • At which line do the QPixmap error occurs? – xlDias Oct 19 '17 at 12:36
3

We have solved it with this:

Install Xvfb and start it with the following command (and export DISPLAY): 

Xvfb :99 -ac -noreset & 
export DISPLAY=:99
qgs = QgsApplication([], True)
instalacia xvfb:
sudo apt-get install python-pip
sudo apt-get install xvfb xserver-xephyr vnc4server
sudo pip install pyvirtualdisplay
| improve this answer | |

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.