scipy: ConvexHull Segfault on OSX with XCode 9.4.1

scikit-image is hitting a segfault using ConvexHull with modern versions of scipy on OSX. You can see a build that calls a short script: https://travis-ci.org/scikit-image/scikit-image/jobs/488320442 A build of https://github.com/scikit-image/scikit-image/pull/3712

/Users/travis/venv/bin/python
Python 3.7.1

     numpy   1.16.1
     scipy   1.2.0
matplotlib   3.0.2
       six   1.12.0
 PIL.Image   1.1.7
  networkx   2.2
    Cython   0.28.1
import numpy as np
from scipy.spatial import ConvexHull
segfaulter = np.array(
        [[ 0. ,  2.5],
         [ 0. ,  3.5],
         [ 0. ,  4.5],
         [ 0. ,  1.5],
         [ 2. ,  5.5],
         [ 2. ,  6.5],
         [ 2. ,  0.5],
         [ 2. , -0.5],
         [ 2.5,  0. ],
         [ 2.5,  6. ],
         [ 3.5,  0. ],
         [ 3.5,  6. ],
         [ 4. ,  5.5],
         [ 4. ,  6.5],
         [ 4. ,  0.5],
         [ 4. , -0.5],
         [ 4.5,  0. ],
         [ 4.5,  6. ],
         [ 5.5,  2. ],
         [ 5.5,  4. ],
         [ 6. ,  2.5],
         [ 6. ,  3.5],
         [ 6. ,  4.5],
         [ 6. ,  1.5],
         [ 6.5,  2. ],
         [ 6.5,  4. ],
         [ 0.5,  2. ],
         [ 0.5,  4. ],
         [-0.5,  2. ],
         [-0.5,  4. ],
         [ 1.5,  0. ],
         [ 1.5,  6. ]], dtype=np.float64)


ConvexHull(segfaulter)
$ python run_segfaulter.py
/Users/travis/.travis/job_stages: line 104: 81648 Segmentation fault: 11  python run_segfaulter.py
The command "python run_segfaulter.py" failed and exited with 139 during .
Your build has been stopped.

Sorry, I’m not too versed in OSX, so maybe somebody else can take it from here šŸ˜•

cc: @jni @cgohlke @stefanv

It could be related to https://github.com/scipy/scipy/issues/5450 ???

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 30 (20 by maintainers)

Commits related to this issue

Most upvoted comments

Just to add another confirmation of this issue. My os is a bit old:

$ xcode-select --version
xcode-select version 2339.
$ uname -a
Darwin dhcp-22-95.ucolick.org 14.5.0 Darwin Kernel Version 14.5.0: Sun Jun  4 21:40:08 PDT 2017; root:xnu-2782.70.3~1/RELEASE_X86_64 x86_64
$ python3
Python 3.7.4 (v3.7.4:e09359112e, Jul  8 2019, 14:54:52)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.version)
3.7.4 (v3.7.4:e09359112e, Jul  8 2019, 14:54:52)
[Clang 6.0 (clang-600.0.57)]

Running the same code as the original poster, I get a Segmentation Fault with scipy==1.3.0. However, it seems the issue was somehow introduced between scipy==1.1.0 and scipy==1.2.0. The call is successful for scipy==1.1.0, but not for scipy==1.2.0 and later.

Just to add another confirmation of this issue. My os is a bit old:

$ xcode-select --version
xcode-select version 2339.
$ uname -a
Darwin dhcp-22-95.ucolick.org 14.5.0 Darwin Kernel Version 14.5.0: Sun Jun  4 21:40:08 PDT 2017; root:xnu-2782.70.3~1/RELEASE_X86_64 x86_64
$ python3
Python 3.7.4 (v3.7.4:e09359112e, Jul  8 2019, 14:54:52)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.version)
3.7.4 (v3.7.4:e09359112e, Jul  8 2019, 14:54:52)
[Clang 6.0 (clang-600.0.57)]

Running the same code as the original poster, I get a Segmentation Fault with scipy==1.3.0. However, it seems the issue was somehow introduced between scipy==1.1.0 and scipy==1.2.0. The call is successful for scipy==1.1.0, but not for scipy==1.2.0 and later.

I had a similar problem when using functions from scipy.spatial and downgrading scipy fixed it for me. Now I use the following

$ xcode-select --version
xcode-select version 2347.
$ uname -a
Darwin ###.### 16.7.0 Darwin Kernel Version 16.7.0: Sun Jun  2 20:26:31 PDT 2019; root:xnu-3789.73.50~1/RELEASE_X86_64 x86_64
$ python --version
Python 3.7.5
$ pip3 list | grep -E "scipy|numpy"
numpy           1.17.4 
scipy           1.1.0 

The 1.2.0 wheels should be built with Mac OS 10.13.3, Apple LLVM 9.1.0 (clang -902.0.39.2), which appears to actually mean LLVM 5.0.2.

The problem scenario described appears to be Apple LLVM version 9.0.0 (clang-900.0.37), which seems to actually be LLVM 4.0.0.

It seems unlikely that the LLVM version discrepancy itself would be a problem with the pre-built SciPy binary pip installed, but maybe there are missing runtime dependencies like libc++ headers. See: https://github.com/youknowone/xcode-libcxx

There seems to be a complicated history of deprecating libstdc++ support and moving to libc++, and having Mac OS distributions very slowly follow suit, with Xcode sometimes missing certain headers?