Search code examples
pythonscipyconvex-hull

I can't find ConvexHull in scipy.spatial


Edit: As far as I can tell it's an issue with the build, I haven't figured out exactly what yet, but I've narrowed it down to that. For anyone reading this, try the suggestion in the marked answer first.

I'm trying to use the ConvexHull function from the scipy library to compute the convex hull for some points, but scipy.spatial.ConvexHull doesn't seem to exist.

The documentation has this as an example:

from scipy.spatial import ConvexHull
points = np.random.rand(30, 2)   # 30 random points in 2-D
hull = ConvexHull(points)

I tried to use this example in my project but couldn't get it to work..

I typed in the appropriate import line but ConvexHull was not found, PyCharm underlined the ConvexHull reference in red, and a mouse-hover shows a 'not found' message.

I've found various mentions on SO about different methods that might be required for importing and using parts of scipy, which I've tried and none of them seem to work, including the import line in the docs example.

I'm running Python 3.6 inside a clean PyCharm venv that I've just created. The pip install of scipy worked fine and scipy is appearing when I try to import it, as is spatial... but ConvexHull doesn't seem to exist.

I'm using scipy 1.1.0, and I've tried using the import that a deleted answer provided...

from scipy.spatial.qhull import ConvexHull... but this didn't work.

Alternately, if this won't work then I am willing to use a different library if possible.


Solution

  • https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.ConvexHull.html

    Did you try

    from scipy import spatial
    spatial.ConvexHull
    

    In 1.0.1 both of these work

    In [2]: spatial.qhull.ConvexHull?
    In [3]: spatial.ConvexHull?
    

    Glancing at the github issues, there may be some build issues, involving cython versions, that may prevent building the qhull file.

    https://github.com/scipy/scipy/issues/8562 - CI: Appveyor builds fail because it can't import ConvexHull from spatial.qhull


    I upgraded to 1.1.0, and had no problem accessing ConvexHull.