问题描述
我在 docker 镜像中同时安装了 shapely 和 geopandas:
copY ["requirement.txt","/app/"]
RUN pip install -r requirement.txt
图像的基础:
FROM python:3.7-slim
在requirements.txt中,我安装了geopandas、shapely和pygeos:
geopandas==0.8.1
pygeos==0.9
Shapely==1.7.1
当我在 docker 容器中运行 python 脚本时,我收到此警告消息:
/usr/local/lib/python3.7/site-packages/geopandas/_compat.py:88: UserWarning: The Shapely GEOS version (3.8.0-CAPI-1.13.1 ) is incompatible with the GEOS version PyGEOS was compiled with (3.9.0-CAPI-1.16.2). Conversions between both will be slow.
shapely_geos_version,geos_capi_version_string
然后我收到此错误消息:
File "SIMILARITY_RANK.py",line 16,in <module>
import geopandas as gpd
File "/usr/local/lib/python3.7/site-packages/geopandas/__init__.py",line 3,in <module>
from geopandas.geoseries import GeoSeries # noqa
File "/usr/local/lib/python3.7/site-packages/geopandas/geoseries.py",line 12,in <module>
from geopandas.base import GeoPandasBase,_delegate_property
File "/usr/local/lib/python3.7/site-packages/geopandas/base.py",line 13,in <module>
from .array import GeometryArray,GeometryDtype
File "/usr/local/lib/python3.7/site-packages/geopandas/array.py",line 25,in <module>
from . import _vectorized as vectorized
File "/usr/local/lib/python3.7/site-packages/geopandas/_vectorized.py",line 39,in <module>
type_mapping = {p.value: _names[p.name] for p in pygeos.GeometryType}
File "/usr/local/lib/python3.7/site-packages/geopandas/_vectorized.py",in <dictcomp>
type_mapping = {p.value: _names[p.name] for p in pygeos.GeometryType}
KeyError: 'MISSING'
pygeos 的安装好像有问题。
我可以在本地虚拟环境中运行代码,所有的包在requirements.txt中都是一样的。
先谢谢你!
解决方法
如前所述in the comment by @Georgy:
请参阅此问题:https://github.com/geopandas/geopandas/issues/1793。看起来使用 0.8.2 版本的 GeoPandas 应该可以解决问题。
GeoPandas 0.8.1 与新的 pygeos 0.9 不兼容。您将需要使用 GeoPandas 0.8.2,它修复了问题或将 pygeos 降级到 0.8。