【问题标题】:Shapely OSError: Could not find lib c or load any of its variants []Shapely OSError:找不到 lib c 或加载它的任何变体 []
【发布时间】:2016-10-12 06:22:31
【问题描述】:

我只是想使用演示代码。我在 Jupyter Notebook 中运行以下命令:

from shapely.geometry import shape

这给了我以下信息:

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 [].

但是,如果我从解释器运行,一切都很好。

知道发生了什么吗?

【问题讨论】:

标签: python shapely


【解决方案1】:

我只是卸载了 Shapely 并重新安装它来解决问题。

python -m pip uninstall shapely

python -m pip install shapely

【讨论】:

  • 科技的奇迹从未停止让我惊叹。
  • pip3 install shapely --upgrade 是另一个对我有用的解决方案。
【解决方案2】:

您可以尝试重置环境变量DYLD_FALLBACK_LIBRARY_PATH

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

Source

【讨论】:

  • 在我的环境中,DYLD_FALLBACK_LIBRARY_PATH 设置为 $(HOME)/anaconda/lib。更改后一切正常。
【解决方案3】:

试试这个可能对你有帮助:

pip install --upgrade --force-reinstall shapely

【讨论】:

    【解决方案4】:

    我修复它的方式:

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

    【讨论】:

      【解决方案5】:

      对我来说,只有在从 shapely lib 安装 Shapely 并从 Anaconda Prompt 执行以下命令后才能工作:

      pip install Shapely-1.7.1-cp37-cp37m-win_amd64.whl --force-reinstall
      

      这会强制重新安装 shapely。

      【讨论】:

        【解决方案6】:

        我必须通过conda update --all 来解决这个问题。

        【讨论】:

          【解决方案7】:

          对于 macOS 用户:

          brew install geos
          pip3 install shapely --upgrade
          

          【讨论】:

            【解决方案8】:

            @user2977865 和@anothernode 的方法是正确的,但它可能并不适合所有人。 默认情况下,shapely 会在 DYLD_PATH 中查找库。

            我已将其设置为 DYLD_LIBRARY_PATH=/usr/local/lib/:/usr/local/mysql/lib/

            但是这些库放在/usr/lib.

            所以我只好修改如下:

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

            注意事项:确保您的环境变量已通过重新启动终端并清除您可能正在使用的任何 IDE 的缓存来设置。

            【讨论】:

              【解决方案9】:

              我在 aws lambda 中运行代码时遇到了一个非常相似的问题,并显示错误消息:

               OSError: Could not find lib c or load any of its variants ['libc.musl-x86_64.so.1'].
              

              我将musl-dev 添加到我的容器安装中并调整了符号链接:

              ln -s /usr/lib/x86_64-linux-musl/libc.so /lib/libc.musl-x86_64.so.1
              

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 2021-02-25
                • 2019-11-10
                • 2013-11-13
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2020-12-05
                相关资源
                最近更新 更多