在docker容器中运行时无法将geopandas导入python

2024-04-29 02:07:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我在docker映像中安装了shapely和geopandas:

COPY ["requirement.txt", "/app/"]
RUN pip install -r requirement.txt

图像的底部:

FROM python:3.7-slim

在requirement.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", line 39, in <dictcomp>
    type_mapping = {p.value: _names[p.name] for p in pygeos.GeometryType}
KeyError: 'MISSING'

似乎pygeos的安装有问题

我可以在本地虚拟环境中运行代码,并且requirement.txt中的所有包都是相同的

提前谢谢你


Tags: inpyimporttxtlibpackagesusrlocal
2条回答

如前所述in the comment by @Georgy

See this issue: https://github.com/geopandas/geopandas/issues/1793. Looks like using 0.8.2 version of GeoPandas should solve the problem.

GeoPandas 0.8.1与新的pygeos 0.9不兼容。您将需要使用GeoPandas 0.8.2,它修复了该问题或将pygeos降级为0.8

试试这个

FROM python:3.8-slim-buster

RUN apt-get update && \
    apt-get install -y gcc python3-dev python3-geopandas

COPY requirements.txt .

RUN pip3 install -r requirements.txt

COPY . .

ENTRYPOINT ["python3"]

相关问题 更多 >