I have a number of data processing scripts that worked a few months ago but now getting seg faults. In one script I had to pull out code from a method and embed in the calling method. In this case, I am performing the simplest of tasks. I am trying to use OGR and Shapely to find the nearest street to a point.

OSX 10.12.6
Python 3.5.2 :: Anaconda custom (x86_64)
Shapely 1.6.1

from osgeo import ogr, osr
from shapely.geometry import Point
def FilterNearbyStreets (self, logLevel, pntSource):
    shpPoint = Point(pntSource.GetX(), pntSource.GetY())
    enoughSegments = False
    bufferSize = 0.001
    while (enoughSegments != True):
        print ("About to buffer {}".format(bufferSize))
        buffer = shpPoint.buffer(bufferSize)
        print ("Buffered!!!")

We never get to Buffered!!!

Segmentation fault: 11

  • How did you install Shapely, with conda or with pip ?
    – gene
    Commented Sep 19, 2017 at 18:27
  • with pip, fairly certain.
    – Cord
    Commented Sep 19, 2017 at 22:44
  • If you use Anaconda, try with conda install shapely
    – gene
    Commented Sep 20, 2017 at 14:46
  • In my experience you can't mix conda install and pip install ever if C extension modules like osgeo.ogr and shapely are involved.
    – sgillies
    Commented Sep 21, 2017 at 14:47
  • Thank you Sean. I am fairly new to Python package management. I started with pip and then ran into a few posts of people advocating conda, so i started using that which is where I believe I ended up in this pickle. I believe your installation instructions use pip which I should have stuck with. I have now cleaned the deck and am trying to go ahead purely with conda.
    – Cord
    Commented Sep 21, 2017 at 15:02

2 Answers 2


Shapely is a C extension module and depends on a specific version of the GEOS shared library. The libgeos.dylib that is included with the Shapely wheels on PyPI (tapped into by pip) is incompatible with the libraries from Anaconda or Conda-Forge (https://conda-forge.org/). Importing Shapely from PyPI loads its shared library and can interfere with Conda packages that depend on GEOS like pyproj, osgeo.ogr, etc. As long as you use an environment that is exclusively a Python virtualenv or a conda environment, and source your packages appropriately for those environments, you'll be fine.


I had a segmentation fault as well with shapely on macOS, I had to reinstall shapely to fix it :

pip uninstall shapely; pip install --no-binary :all: shapely

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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