Home > Net >  Getting "AttributeError: module 'shapely.geos' has no attribute 'lgeos'&quo
Getting "AttributeError: module 'shapely.geos' has no attribute 'lgeos'&quo

Time:01-26

I am trying to do this exercise from momepy (https://github.com/pysal/momepy/blob/main/docs/user_guide/getting_started.ipynb), but on the third codeblock

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

I got the following error

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'

Not entirely sure if I am missing a module or if there are library incompatibilities

CodePudding user response:

In the new version(2.0.0 released on 12 December 2022) of shapely there is no attribute 'lgeos'.

Link to document:

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

You can check version by:

shapely.__version__

If you want to use lgeos in your code you can downgrade your version to 1.8.5

%pip install shapely==1.8.5

I was able to successfully import on version 1.8.5 on Jupyter.

from shapely.geos import lgeos
  • Related