【问题标题】:ImportError: Spatial indexes require either `rtree` or `pygeos` in geopanda but rtree is installedImportError:空间索引在 geopanda 中需要“rtree”或“pygeos”,但已安装 rtree
【发布时间】:2021-10-20 09:37:43
【问题描述】:

我正在尝试在 python 中剪辑空间数据,但是当我运行我的代码时...

europe = gpd.clip(worldmap, europe_bound_gdf)

...我收到错误:

(ImportError: Spatial indexes require either rtreeorpygeos`.)

当我尝试使用以下方式安装 rtree 时:

pip3 install rtree

有人告诉我:

Requirement already satisfied: rtree in /Users/joshuajones/.pyenv/versions/3.9.4/lib/python3.9/site-packages (0.9.7`)

那么为什么我的代码不起作用?

【问题讨论】:

  • 你确定在同一个环境下安装rtree

标签: python gis geopandas


【解决方案1】:

我遇到了同样的问题,这为我解决了:

pip uninstall rtree
sudo apt install libspatialindex-dev
pip install rtree

找到答案here

【讨论】:

    【解决方案2】:

    就我而言,唯一有帮助的是:

    安装并导入condalab,运行两次。

    !pip install -q condacolab -q
    
    import condacolab
    
    condacolab.install()
    

    安装 geopandas,这可能需要很长时间

    !conda install geopandas
    
    import geopandas as gpd
    

    【讨论】:

      【解决方案3】:

      GStav's answer 为我工作,但作为 Mac 用户,我的步骤略有不同:

      pip uninstall rtree
      brew install spatialindex
      pip install rtree
      

      【讨论】:

      • 这对我有用 arch -arm64 brew install spatialindex
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-09-29
      • 1970-01-01
      • 2020-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多