# Python shell segmentation fault after exiting when importing pygplates

**URL:** https://discourse.gplates.org/t/python-shell-segmentation-fault-after-exiting-when-importing-pygplates/487
**Category:** Bug Reports
**Created:** [3 March 2022 03:20 UTC](https://discourse.gplates.org/t/python-shell-segmentation-fault-after-exiting-when-importing-pygplates/487 "2022-03-03T03:20:01Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![vinnie](https://discourse.gplates.org/letter_avatar_proxy/v4/letter/v/71e660/32.png) [@vinnie](https://discourse.gplates.org/u/vinnie)
#### Post date: [3 March 2022 03:20 UTC](https://discourse.gplates.org/t/python-shell-segmentation-fault-after-exiting-when-importing-pygplates/487/1 "2022-03-03T03:20:01Z")

</div>

I am trying to build pygplates from source for python 3.9.10 on debian11-bullseye (python:3.9.10-slim-buster on dockerhub), but when importing pygplates in the python code, after exiting (exit()), python shell returns segmentation fault . Not sure if any of the functionalities of pygplates are affected but this is concerning to me

The commands I use to install in the container:

```auto
apt-get update
apt-get install -y cmake libglew-dev python3-dev libboost-dev libboost-python-dev libboost-thread-dev libboost-program-options-dev libboost-test-dev libboost-system-dev libqt5opengl5-dev libqt5svg5-dev libqt5xmlpatterns5-dev libgdal-dev libcgal-dev libproj-dev libqwt-qt5-dev zlib1g-dev libfreetype6-dev libfontconfig1-dev libxrender-dev libice-dev libsm-dev qt5-qmake curl unzip
# qt5-default package replaced by qt5-qmake
curl -L -k https://downloads.sourceforge.net/project/gplates/pygplates/beta-revision-28/pygplates_rev28_src.zip > pygplates_rev28_src.zip
unzip pygplates_rev28_src.zip && rm pygplates_rev28_src.zip
export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal
cd /usr/src/pygplates_rev28_src/
cmake .
make -j 4 pygplates

```

also, when compiling the binaries, lots of warning appear as described here, not sure if this affects installation [Pygplates warnings from boost](https://discourse.gplates.org/t/pygplates-warnings-from-boost/202)

dependencies info:

```auto
||/ Name Version Architecture Description
+++-==================================-====================-============-=====================================================================
ii cmake 3.18.4-2+deb11u1 amd64 cross-platform, open-source make system
ii g++ 4:10.2.1-1 amd64 GNU C++ compiler
ii libboost-dev:amd64 1.74.0.3 amd64 Boost C++ Libraries development files (default version)
ii libboost-program-options-dev:amd64 1.74.0.3 amd64 program options library for C++ (default version)
ii libboost-python-dev 1.74.0.3 amd64 Boost.Python Library development files (default version)
ii libboost-system-dev:amd64 1.74.0.3 amd64 Operating system (e.g. diagnostics support) library (default version)
ii libboost-test-dev:amd64 1.74.0.3 amd64 components for writing and executing test suites (default version)
ii libboost-thread-dev:amd64 1.74.0.3 amd64 portable C++ multi-threading (default version)
ii libcgal-dev:amd64 5.2-3 amd64 C++ library for computational geometry (development files)
ii libfontconfig1-dev:amd64 2.13.1-4.2 amd64 generic font configuration library - dummy package
ii libfreetype6-dev:amd64 2.10.4+dfsg-1 amd64 FreeType 2 font engine, development files (transitional package)
ii libgdal-dev 3.2.2+dfsg-2+deb11u1 amd64 Geospatial Data Abstraction Library - Development files
ii libglew-dev:amd64 2.1.0-4+b1 amd64 OpenGL Extension Wrangler - development environment
ii libice-dev:amd64 2:1.0.10-1 amd64 X11 Inter-Client Exchange library (development headers)
ii libproj-dev:amd64 7.2.1-1 amd64 Cartographic projection library (development files)
ii libqt5opengl5-dev:amd64 5.15.2+dfsg-9 amd64 Qt 5 OpenGL library development files
ii libqt5svg5-dev:amd64 5.15.2-3 amd64 Qt 5 SVG module development files
ii libqt5xmlpatterns5-dev:amd64 5.15.2-3 amd64 Qt 5 XML patterns development files
ii libqwt-qt5-dev 6.1.4-2 amd64 Qt widgets library for technical applications (development, qt5)
ii libsm-dev:amd64 2:1.2.3-1 amd64 X11 Session Management library (development headers)
ii libxrender-dev:amd64 1:0.9.10-1 amd64 X Rendering Extension client library (development files)
ii python3-dev 3.9.2-3 amd64 header files and a static library for Python (default)
ii zlib1g-dev:amd64 1:1.2.11.dfsg-2 amd64 compression library - development
ii libgl1-mesa-dev:amd64 20.3.5-1 amd64 transitional dummy package
ii libgl1-mesa-dri:amd64 20.3.5-1 amd64 free implementation of the OpenGL API -- DRI modules
ii libglu1-mesa:amd64 9.0.1-1 amd64 Mesa OpenGL utility library (GLU)
ii libglu1-mesa-dev:amd64 9.0.1-1 amd64 Mesa OpenGL utility library -- development files

```

I am able to build from source and use pygplates on python3.7 on debian10-buster (python:3.7.10 from dockerhub) without any issues but would like to upgrade to debian11 and python 3.9.

---

<div class="post-metadata">

### Author: ![john.cannon](https://discourse.gplates.org/letter_avatar_proxy/v4/letter/j/3e96dc/32.png) [@john.cannon](https://discourse.gplates.org/u/john.cannon)
#### Post date: [3 March 2022 04:01 UTC](https://discourse.gplates.org/t/python-shell-segmentation-fault-after-exiting-when-importing-pygplates/487/2 "2022-03-03T04:01:10Z")

</div>

Hi vinnie,

It’s an issue with version 3.9 of Python (when using pyGPlates). As you noted the seg fault happens on exiting. I’m currently looking into it and will let you know when it’s fixed (it looks to be a reference count issue in a boost-python object somewhere).

In regard to the warning messages you mentioned, there’s more recent source code (revision 33) mentioned in [this post](https://discourse.gplates.org/t/splitting-isochrons-bisected-by-future-ridge-pygplates/449/8) but it won’t fix the above seg fault.

---

<div class="post-metadata">

### Author: ![vinnie](https://discourse.gplates.org/letter_avatar_proxy/v4/letter/v/71e660/32.png) [@vinnie](https://discourse.gplates.org/u/vinnie)
#### Post date: [3 March 2022 04:23 UTC](https://discourse.gplates.org/t/python-shell-segmentation-fault-after-exiting-when-importing-pygplates/487/3 "2022-03-03T04:23:46Z")

</div>

Hi John,  
Thanks for the quick reply! Would you know if the issue with Python3.9 affects anything besides seg faulting when exiting the shell? This is something I’m willing to ignore in the meantime if that’s all the extent of the issue.

---

<div class="post-metadata">

### Author: ![john.cannon](https://discourse.gplates.org/letter_avatar_proxy/v4/letter/j/3e96dc/32.png) [@john.cannon](https://discourse.gplates.org/u/john.cannon)
#### Post date: [3 March 2022 04:41 UTC](https://discourse.gplates.org/t/python-shell-segmentation-fault-after-exiting-when-importing-pygplates/487/4 "2022-03-03T04:41:24Z")

</div>

I think generally it’s probably OK - this particular crash is happening inside pyGPlates (when it cleans up after itself) - _well, not exactly inside pygplates but essentially that’s what’s happening_.

However Python would return a non-zero error code, so any scripts calling Python might exit there (if they check the return code). And it’s possible some resources inside Python might not get cleaned up (eg, if you also imported other modules besides pygplates that had temporary files, etc, then they might not get removed, that sort of thing).

---

<div class="post-metadata">

### Author: ![john.cannon](https://discourse.gplates.org/letter_avatar_proxy/v4/letter/j/3e96dc/32.png) [@john.cannon](https://discourse.gplates.org/u/john.cannon)
#### Post date: [22 March 2022 10:47 UTC](https://discourse.gplates.org/t/python-shell-segmentation-fault-after-exiting-when-importing-pygplates/487/5 "2022-03-22T10:47:41Z")

</div>

Here’s pyGPlates [version 0.35](https://cloudstor.aarnet.edu.au/plus/s/20H6yzYQkXaQ29f) that fixes the seg fault on exit with Python 3.9 (_also I’ve changed the versioning from revision 35 to “0.35”_).

This also contains the first Apple M1 build of pyGPlates.
