When use pyqgis+python for auto-mapping, I encounter a tricky Segmentation fault (core dumped) error, at the 2nd run of the program. I checked previous similar post but not able to fix the issue.

I have a simple function: test_qgis.py, with content:

def test_QGIS_init():
    app = QgsApplication([], True)
    QgsApplication.setPrefixPath('/usr', True)
    ##do the processing, cropping polygon, produce map, etc.

and then test with a test file "test.py" in the same folder:

import test_qgis
print '-------------------test qgis start -------------'
print '-------------------test qgis 2nd round -------------'

The output will be fine for the 1st run, but failed at the 2nd time.

-------------------test qgis start -------------
-------------------test qgis 2nd round -------------
Segmentation fault (core dumped)

Any clue?

It it also interesting that, 1) turn on the exitQgis() at the end of the function does not help; 2)if I run the test through X server remotely, then the test passes without the Segmentation fault error.

I would try to keep this version of pyqgis as some function I have tested only working on this version.

Here is my system information: OS version

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.6 LTS
Release:        16.04
Codename:       xenial


$ python
Python 2.7.12 (default, Aug 22 2019, 16:36:40)
[GCC 5.4.0 20160609] on linux2


>>> from qgis.core import QGis
u'Las Palmas'
  • If I turn QgsApplication.setPrefixPath('/usr', **True**) to False, then the 1st run will also fail at: ... ms=QgsMapSettings(); .... composition= QgsComposition(ms); ... document = QtXml.QDomDocument(); ... composition.loadFromTemplate(document) error message: Segmentation fault (core dumped). This link mentioned similar error, but no clear solution. – Chui Sep 17 '19 at 17:42

Your Answer

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

Browse other questions tagged or ask your own question.