Why do I get an error when trying to read a file in geopanda's included datasets?
Asked Answered
N

1

6

I've just installed Anaconda in my new laptop, and created an environment with geopandas installed in it. I've tried to upload the world map that comes with geopandas through the following code:

import geopandas as gpd
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))

But I obtain the following error message:

File ~/anaconda3/envs/mapas_test/lib/python3.8/site-packages/shapely/geometry/base.py:854, in BaseMultipartGeometry.__array_interface__(self)
    851 @property
    852 def __array_interface__(self):
    853     """Provide the Numpy array protocol."""
--> 854     raise NotImplementedError("Multi-part geometries do not themselves "
    855                               "provide the array interface")

NotImplementedError: Multi-part geometries do not themselves provide the array interface

Since this error has never appeared in my old laptop, I guess it is related to some problem during installation, but I could be wrong. Here are the technical details about the installation.

OS: Ubuntu 22.04.1

Python version: 3.9.12

Conda version 4.13.0

geopandas version 0.9.0

Shapely version 1.7.1

And not sure if it is relevant, but the only other package installed in the environment is jupyter version 1.0.0

Nolin answered 13/8, 2022 at 19:8 Comment(2)
shapely 1.7.1 is two years old and doesn't support the vectorized operations geopandas now relies on. some parts of the API should still work, but some quick googling suggests that others who have encountered this error found it was resolved by upgrading shapely to >= 1.8.1Dentoid
Also if you’re mixing anaconda with conda forge you’re headed for trouble. See https://mcmap.net/q/1769613/-problem-while-installing-geopandas-with-conda-anacondaDentoid
M
14

This is caused by incompatibility of shapely 1.7 and numpy 1.23. Either update shapely to 1.8 or downgrade numpy, otherwise it won't work.

Misdirect answered 14/8, 2022 at 20:22 Comment(4)
It worked! One additional issue I had was that shapely 1.8 was not avaliable in conda, so I had to use pip to upgrade it, but now my programs no longer display errors. Thank you!Nolin
@Nolin the conda-forge channel has more recent versions of shapely. The anaconda channel always lags and creates problems when mixing in from Conda Forge. Many users simply avoid anaconda channel altogether.Adler
What is the appropriate numpy downgrade verson? Conda is taking far too long to resolve for shapely=1.8.Fanlight
Anything older that than 1.23. 1.22 should work.Misdirect

© 2022 - 2024 — McMap. All rights reserved.