读取Geopandas内置数据集报错:Multi-part geometries不提供数组接口
解决GeoPandas读取内置数据集时的
NotImplementedError错误 问题重现
运行以下代码读取GeoPandas自带的世界地图数据集:
import geopandas as gpd world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
触发如下错误:
File ~/anaconda3/envs/mapas_test/lib/python3.8/site-packages/shapely/geometry/base.py:854, in BaseMultipartGeometry.__array_interface__(self) 851 @property 852 def __array_interface__(self): 853 """Provide the Numpy array protocol.""" --> 854 raise NotImplementedError("Multi-part geometries do not themselves " 855 "provide the array interface") NotImplementedError: Multi-part geometries do not themselves provide the array interface
环境信息
- OS:Ubuntu 22.04.1
- Python:3.9.12
- Conda:4.13.0
- GeoPandas:0.9.0
- Shapely:1.7.1
- 额外安装:jupyter 1.0.0
解决方案
方案1:升级Shapely到兼容版本
Shapely 1.7.1在Ubuntu 22.04环境下与GeoPandas 0.9.0存在兼容性问题,升级到1.8.x版本可修复该错误:
conda install shapely=1.8.5 -c conda-forge
方案2:重建环境,使用conda-forge统一安装依赖
直接通过conda-forge创建新环境并安装GeoPandas,让包管理器自动匹配所有依赖的兼容版本,避免手动安装导致的冲突:
conda remove -n mapas_test --all conda create -n mapas_test python=3.9 geopandas=0.9.0 jupyter -c conda-forge conda activate mapas_test
方案3:降级numpy版本(可选)
若升级Shapely后仍报错,可能是numpy版本过高引发的适配问题,尝试降级到1.21.x系列:
conda install numpy=1.21.6
验证
重新运行测试代码,若能成功加载naturalearth_lowres数据集则问题解决。
内容的提问来源于stack exchange,提问作者Fernando
相关产品推荐
相关产品推荐

