python-3.x 获取“属性错误:模块“shapely.geos”没有属性“lgeos”

7gcisfzg  于 2023-01-27  发布在  Python
关注(0)|答案(1)|浏览(669)

我尝试从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'

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

im9ewurl

im9ewurl1#

在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

相关问题