运行momepy入门代码遇AttributeError: shapely.geos无lgeos属性
解决AttributeError: module 'shapely.geos' has no attribute 'lgeos'
这个错误是Shapely版本不兼容导致的:Shapely 2.0及以上版本重构了内部API,移除了lgeos属性,而你当前环境里的momepy或其依赖库仍在调用这个旧属性。
解决方案步骤:
- 先检查当前Shapely版本:
或者在终端运行:import shapely print(shapely.__version__)pip show shapely - 降级Shapely到1.x稳定版本(推荐1.8.5.post1):
pip install shapely==1.8.5.post1 --force-reinstall - 重新运行目标代码块:
f, ax = plt.subplots(figsize=(10, 10)) buildings.plot(ax=ax) ax.set_axis_off() plt.show()
额外建议
如果后续安装其他地理库时再次触发版本升级,建议使用虚拟环境(如venv、conda环境)隔离momepy项目的依赖,避免不同项目间的版本冲突。
内容的提问来源于stack exchange,提问作者Reuben
相关产品推荐
相关产品推荐

