首页 > 解决方案 > AttributeError:模块“shapely”没有属性“affinity”

问题描述

在 Windows 中安装 shapely 后(从https://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely下载 .whl 文件)出现以下错误:

from shapely.geometry import Point
Traceback (most recent call last):

  File "<ipython-input-48-df8e65c5217a>", line 1, in <module>
    from shapely.geometry import Point

  File "C:\Anaconda3\lib\site-packages\shapely\geometry\__init__.py", line 23, in <module>
    import shapely.speedups

  File "C:\Anaconda3\lib\site-packages\shapely\speedups\__init__.py", line 99, in <module>
    enable()

  File "C:\Anaconda3\lib\site-packages\shapely\speedups\__init__.py", line 69, in enable
    _orig['affine_transform'] = shapely.affinity.affine_transform

AttributeError: module 'shapely' has no attribute 'affinity'

标签: pythonshapely

解决方案


首先使用同一站点安装 Shapely 的依赖项。对我来说,以下程序有效。我在 Windows 64 位上使用 python 3.6。

按以下顺序安装车轮:

1: GDAL-2.4.1-cp36-cp36m-win_amd64.whl

2: Fiona-1.8.6-cp36-cp36m-win_amd64.whl

3: Shapely-1.6.4.post2-cp36-cp36m-win_amd64.whl

这应该会导致正确安装 Shapely 模块。


推荐阅读