Shapely OSError: Could not find lib c or load any of its variants []

女生的网名这么多〃 提交于 2020-12-02 16:26:12

问题


I'm just trying to use the demo code. I run the following in Jupyter Notebook:

from shapely.geometry import shape

Which gives me the following:

OSError                                   Traceback (most recent call last)
<ipython-input-4-cf5b4d0962ea> in <module>()
----> 1 from shapely.geometry import shape

/Users/hkwik/anaconda/lib/python2.7/site-packages/shapely/geometry/__init__.py in <module>()
      2 """
      3 
----> 4 from .base import CAP_STYLE, JOIN_STYLE
      5 from .geo import box, shape, asShape, mapping
      6 from .point import Point, asPoint

/Users/hkwik/anaconda/lib/python2.7/site-packages/shapely/geometry/base.py in <module>()
      7 from ctypes import pointer, c_size_t, c_char_p, c_void_p
      8 
----> 9 from shapely.coords import CoordinateSequence
     10 from shapely.ftools import wraps
     11 from shapely.geos import lgeos, ReadingError

/Users/hkwik/anaconda/lib/python2.7/site-packages/shapely/coords.py in <module>()
      6 from ctypes import byref, c_double, c_uint
      7 
----> 8 from shapely.geos import lgeos
      9 from shapely.topology import Validating
     10 

/Users/hkwik/anaconda/lib/python2.7/site-packages/shapely/geos.py in <module>()
     81         _lgeos = load_dll('geos_c', fallbacks=alt_paths)
     82 
---> 83     free = load_dll('c').free
     84     free.argtypes = [c_void_p]
     85     free.restype = None

/Users/hkwik/anaconda/lib/python2.7/site-packages/shapely/geos.py in load_dll(libname, fallbacks, mode)
     59         raise OSError(
     60             "Could not find lib {0} or load any of its variants {1}.".format(
---> 61                 libname, fallbacks or []))
     62 
     63 _lgeos = None

OSError: Could not find lib c or load any of its variants [].

However, if I run from the interpreter, everything is fine.

Any idea what's going on?


回答1:


You may try to reset the environment variable DYLD_FALLBACK_LIBRARY_PATH:

export DYLD_FALLBACK_LIBRARY_PATH=$(HOME)/lib:/usr/local/lib:/lib:/usr/lib

Source




回答2:


I simply uninstalled Shapely and re-installed it to fix the issue.

python -m pip uninstall shapely

python -m pip install shapely



回答3:


The way I fixed it:

apk add geos libc-dev musl-dev
pip install Shapely



回答4:


@user2977865 and @anothernode are correct in their approach but it may not work for everyone. By default, shapely will look for libraries in the DYLD_PATH.

I had it set to DYLD_LIBRARY_PATH=/usr/local/lib/:/usr/local/mysql/lib/

But these libraries are placed in /usr/lib.

So I had to modify it as follows:

export DYLD_LIBRARY_PATH=/usr/lib/:/usr/local/mysql/lib/

Bonus note: Ensure that your environment variables have been set by restarting terminal and clearing cache of any IDEs you might be using.



来源:https://stackoverflow.com/questions/39991765/shapely-oserror-could-not-find-lib-c-or-load-any-of-its-variants

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!