osmnx安装是否存在通用Bug?无法导入shapely.geos.TopologicalError
解决osmnx导入时无法找到shapely.geos.TopologicalError的问题
问题根源
这个错误基本是shapely版本与osmnx版本不兼容导致的:较新的shapely(2.0及以上)已经将TopologicalError迁移到shapely.errors模块下,而旧版osmnx仍在从shapely.geos路径中导入该类。
修复步骤
1. 检查当前shapely版本
激活你的conda环境后,执行命令查看版本:
conda list shapely
如果版本显示为2.0+,就需要调整版本适配。
2. 降级shapely到兼容版本
osmnx v1.3.0及以下版本需要依赖shapely 1.x系列,执行以下命令降级:
conda install shapely=1.8.5
也可以在安装osmnx时直接指定兼容的shapely版本:
conda install osmnx shapely=1.8.5
3. 验证修复效果
重启Python环境后,尝试导入osmnx:
import osmnx as ox
若未报错,说明问题已解决。
备选方案:升级osmnx到最新版
如果不想降级shapely,可以尝试升级osmnx到支持shapely 2.x的版本:
conda update osmnx
注意:升级前建议备份当前环境,避免其他依赖出现冲突。
内容的提问来源于stack exchange,提问作者SYC
相关产品推荐
相关产品推荐

