【问题标题】:Getting "AttributeError: module 'shapely.geos' has no attribute 'lgeos'"获取 \"AttributeError: 模块 \'shapely.geos\' 没有属性 \'lgeos\'\"
【发布时间】:2023-01-24 23:32:19
【问题描述】:

我正在尝试从 momepy (https://github.com/pysal/momepy/blob/main/docs/user_guide/getting_started.ipynb) 做这个练习,但是在第三个代码块上

f, ax = plt.subplots(figsize=(10, 10))
buildings.plot(ax=ax)
ax.set_axis_off()
plt.show()

我收到以下错误

AttributeError                            Traceback (most recent call last)
Cell In[12], line 5
      1 buildings = gpd.read_file(momepy.datasets.get_path('bubenec'),
      2                           layer='buildings')
      4 f, ax = plt.subplots(figsize=(10, 10))
----> 5 buildings.plot(ax=ax)
      6 ax.set_axis_off()
      7 plt.show()

File ~/miniconda3/envs/testbed/lib/python3.10/site-packages/geopandas/plotting.py:925, in GeoplotAccessor.__call__(self, *args, **kwargs)
    923 kind = kwargs.pop("kind", "geo")
    924 if kind == "geo":
--> 925     return plot_dataframe(data, *args, **kwargs)
    926 if kind in self._pandas_kinds:
    927     # Access pandas plots
    928     return PlotAccessor(data)(kind=kind, **kwargs)

File ~/miniconda3/envs/testbed/lib/python3.10/site-packages/geopandas/plotting.py:689, in plot_dataframe(df, column, cmap, color, ax, cax, categorical, legend, scheme, k, vmin, vmax, markersize, figsize, legend_kwds, categories, classification_kwds, missing_kwds, aspect, **style_kwds)
    686     markersize = df[markersize].values
    688 if column is None:
--> 689     return plot_series(
    690         df.geometry,
    691         cmap=cmap,
    692         color=color,
...
---> 67     geom = shapely.geos.lgeos.GEOSGeom_clone(geom._ptr)
     68     return shapely.geometry.base.geom_factory(geom)
     70 # fallback going through WKB

AttributeError: module 'shapely.geos' has no attribute 'lgeos'

不完全确定我是否缺少模块或库不兼容

【问题讨论】:

    标签: python geopandas shapely geos


    【解决方案1】:

    在 shapely 的新版本(2022 年 12 月 12 日发布的 2.0.0)中,没有属性“lgeos”。

    文档链接:

    https://pypi.org/project/Shapely/#history

    您可以通过以下方式检查版本:

    shapely.__version__
    

    如果你想在你的代码中使用lgeos,你可以将你的版本降级到1.8.5

    !pip install shapely==1.8.5
    

    我能够在 Jupyter 上成功导入 1.8.5 版。

    from shapely.geos import lgeos
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-14
      • 2019-02-18
      • 1970-01-01
      • 2021-08-12
      • 2020-01-01
      • 2019-07-20
      相关资源
      最近更新 更多