0

I had installed QGIS with it in ubuntu :

sudo apt-get install qgis python-qgis qgis-plugin-grass

refer to this guide : https://www.qgis.org/en/site/forusers/alldownloads.html

then i try to import QGIS module that usually work in Windows QGIS Desktop application such as :

from qgis.core import *
from osgeo import *

but then, i try to :

import processing

and it said:

No module named processing

Ok i see since this is run as external application, so i try to do something like this:

import sys
sys.path.append('/usr/share/qgis/python/plugins')
import processing

but what i've got is:

QPixmap: Must construct a QApplication before a QPaintDevice
Aborted (core dumped)

Then i my python console was exited automatically

So my question is, how to import processing in ubuntu python console that had been QGIS installed?

I really need this module..

6
  • May be this is what you are looking for: gis.stackexchange.com/questions/206620/…, because if you are not inside qgis, you need a standalone python script which initializes the qgis "environment". Commented Feb 22, 2018 at 10:46
  • but everytime i do this QApplication([]), it said "cannot connect to X server" Commented Feb 22, 2018 at 10:59
  • uhh, all right, you are on telnet/ssh connection? There are gui components, which need access the X-Window. Don't know exactly what to do in such a case. Commented Feb 22, 2018 at 11:09
  • i found this, if the above is the case: osgeo-org.1560.x6.nabble.com/… Commented Feb 22, 2018 at 11:15
  • i use ubuntu in virtualenv by the way.. Commented Feb 22, 2018 at 11:49

1 Answer 1

2

refer to this link, http://osgeo-org.1560.x6.nabble.com/Error-cannot-connect-to-X-server-on-Ubuntu-td5177029.html

This is how to import processing

import os 
import sys 

qgisprefix = '/usr' 
#qgisprefix='/usr/share/qgis/resources' 

# configure paths for QGIS 
sys.path.insert(0, qgisprefix+'/share/qgis/python') 
sys.path.insert(1, qgisprefix+'/share/qgis/python/plugins') 

# disable QGIS debug messages 
#os.environ['QGIS_DEBUG'] = '-1' 
os.environ['DISPLAY']="" 
# import QGIS modules 
from qgis.core import * 

#from qgis.gui import * 

# configure QGIS paths 
QgsApplication.setPrefixPath(qgisprefix, False) 

# initalise QGIS 
QgsApplication.initQgis() 

app = QgsApplication([], False) 

import processing

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