0

I am trying to run the default script that PyQGIS Cookbook provides along with adding few lines to read my project. It tries to read the read project but at the end gives a Segmentation Fault. How can I fix this?

import sys
sys.path.append('/Applications/QGIS3.app/Contents/Resources/python')

from qgis.core import *

# supply path to qgis install location
QgsApplication.setPrefixPath("/Applications/QGIS3.app/Contents/MacOS", True)

# create a reference to the QgsApplication, setting the
# second argument to False disables the GUI
qgs = QgsApplication([], False)

# load providers
qgs.initQgis()

project = QgsProject.instance()
project.read('‎⁨polygondata.qgs')
print(project.fileName())
print(project.mapLayers())

# Write your code here to load some layers, use processing
# algorithms, etc.

# When your script is complete, call exitQgis() to remove the
# provider and layer registries from memory

qgs.exitQgis()
0

I actually found the way to do it. You have to set this:

export QT_QPA_PLATFORM_PLUGIN_PATH=/Applications/QGIS3.app/Contents/Plugins/platforms/

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.