简体   繁体   English

匀称的 OSError:找不到 lib c 或加载其任何变体 []

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

I'm just trying to use the demo code.我只是想使用演示代码。 I run the following in Jupyter Notebook:我在 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?知道发生了什么吗?

I simply uninstalled Shapely and re-installed it to fix the issue.我只是卸载了 Shapely 并重新安装它来解决这个问题。

python -m pip uninstall shapely

python -m pip install shapely

You may try to reset the environment variable DYLD_FALLBACK_LIBRARY_PATH :您可以尝试重置环境变量DYLD_FALLBACK_LIBRARY_PATH

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

Source 来源

The way I fixed it:我修复它的方式:

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

For me, only works after installing Shapely from the shapely lib and executing the following command from Anaconda Prompt:对我来说,只有在从shapely lib安装 Shapely 并从 Anaconda Prompt 执行以下命令后才有效:

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

This forces a re-install of shapely.这迫使重新安装匀称的。

@user2977865 and @anothernode are correct in their approach but it may not work for everyone. @user2977865 和 @anothernode 的方法是正确的,但它可能不适用于所有人。 By default, shapely will look for libraries in the DYLD_PATH .默认情况下, shapely将在DYLD_PATH查找库。

I had it set to DYLD_LIBRARY_PATH=/usr/local/lib/:/usr/local/mysql/lib/我将它设置为DYLD_LIBRARY_PATH=/usr/local/lib/:/usr/local/mysql/lib/

But these libraries are placed in /usr/lib .但是这些库被放置在/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.额外说明:通过重新启动终端并清除您可能正在使用的任何 IDE 的缓存,确保已设置您的环境变量。

I had a very similar issue running code in aws lambda with the error message:我在 aws lambda 中运行代码时遇到了一个非常相似的问题,并显示错误消息:

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

I added musl-dev to my container installation and adapted the symlink:我将musl-dev添加到我的容器安装中并调整了符号链接:

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

我不得不做一个conda update --all来解决这个问题。

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

pip install --upgrade --force-reinstall shapely

For macOS users:对于 macOS 用户:

brew install geos
pip3 install shapely --upgrade

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 导入 geopandas 时出错 OSError: 找不到 lib c 或加载其任何变体 [] - Error when importing geopandas OSError: Could not find lib c or load any of its variants [] OSError:找不到 geos_c.dll 或加载其任何变体 - OSError: Could not find geos_c.dll or load any of its variants 找不到库 geos_c 或加载其任何变体 - Could not find library geos_c or load any of its variants 安装Shapely时找不到OSError geos_c - OSError geos_c could not be found when Installing Shapely OSError: 无法找到或加载 spatialindex_c.dll - OSError: could not find or load spatialindex_c.dll 安装 Shapely: OSError: [WinError 126] 找不到指定的模块 - Install Shapely: OSError: [WinError 126] The specified module could not be found OSError:CUDA lib64路径无法位于/ usr / lib64中 - OSError: The CUDA lib64 path could not be located in /usr/lib64 OSError:找不到 kaggle.json。 确保它位于 C:\Users\Lior\.kaggle 中。 或者使用环境方法 - OSError: Could not find kaggle.json. Make sure it's located in C:\Users\Lior\.kaggle. Or use the environment method Autoit Pyinstaller OSError:无法从路径加载 AutoItX:C:\\Users\\AppData\\Local\\Temp\\_MEI74002\\autoit\\lib\\AutoItX3_x64.dll - Autoit Pyinstaller OSError: Cannot load AutoItX from path: C:\Users\AppData\Local\Temp\_MEI74002\autoit\lib\AutoItX3_x64.dll OSError:找不到合适的 TLS CA 证书包 - OSError: Could not find a suitable TLS CA certificate bundle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM