I installed both shapely and geopandas in the docker image:
COPY ["requirement.txt", "/app/"]
RUN pip install -r requirement.txt
The base of the image:
FROM python:3.7-slim
In the requirement.txt, I have geopandas, shapely and pygeos installed:
geopandas==0.8.1
pygeos==0.9
Shapely==1.7.1
When I run the python script in the docker container, I am receiving this warning message:
/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
and following that I am receiving this error message:
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'
It seems something is wrong with the installation of pygeos.
I could run the code in the local virtual environment, and all the packages are the same in the requirement.txt.
Thank you in advance!
question from:
https://stackoverflow.com/questions/65921476/cant-import-geopandas-to-python-when-running-in-docker-container 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…