![](/img/trans.png)
[英]Error when importing geopandas OSError: Could not find lib c or load any of its variants []
[英]Shapely OSError: Could not find lib c or load any of its variants []
我只是想使用演示代碼。 我在 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 [].
但是,如果我從解釋器運行,一切都很好。
知道發生了什么嗎?
我只是卸載了 Shapely 並重新安裝它來解決這個問題。
python -m pip uninstall shapely
python -m pip install shapely
您可以嘗試重置環境變量DYLD_FALLBACK_LIBRARY_PATH
:
export DYLD_FALLBACK_LIBRARY_PATH=$(HOME)/lib:/usr/local/lib:/lib:/usr/lib
我修復它的方式:
apk add geos libc-dev musl-dev
pip install Shapely
對我來說,只有在從shapely lib安裝 Shapely 並從 Anaconda Prompt 執行以下命令后才有效:
pip install Shapely-1.7.1-cp37-cp37m-win_amd64.whl --force-reinstall
這迫使重新安裝勻稱的。
@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 的緩存,確保已設置您的環境變量。
我在 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
我不得不做一個conda update --all
來解決這個問題。
試試這個可能對你有幫助:
pip install --upgrade --force-reinstall shapely
對於 macOS 用戶:
brew install geos
pip3 install shapely --upgrade
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.