Tuesday, 12 November 2019

qgis - Seg Faults and Instantiation Errors while running PyQGIS on OS X


I'm having issues getting off the ground with running PyQGIS on my OS X. I'm frankly very confused as some errors occur sporadically while executing the same code.


When I try the following:


QgsApplication.setPrefixPath('/Applications/QGIS.app/Contents/MacOS', True)
QgsApplication.initQgis()
QgsProviderRegistry.instance().providerList()

I either get one of three scenarios:




  • Segmentation fault: 11 when returning the list

  • A blank list returned


  • Or a this error after initQgis()...


    QCoreApplication::applicationDirPath: Please instantiate the QApplication object first QWidget: Must construct a QApplication before a QPaintDevice




A workaround I found to work is to instantiate a QgsApplication object first as the error suggests with something like


app = QgsApplication([], True)


However, the problem here is that this creates a GUI which I don't need - I'm just trying to do some scripting. If I change the instantiation parameter to False, then I get an error with initQgis() of:


QWidget: Cannot create a QWidget when no GUI is being used

Also, in a lot of examples I've found online you don't need the instantiation step... is there something funky with my setup?


I'm using a venv if that makes any difference... all commands I want to run work normally in the QGIS Python console, it's just the external script that's giving me issues.


Any thoughts?


Python: 2.7.10, QGIS: 2.10.1-Pisa, OS X: 10.10.3




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...