1

good afternoon, I've been working with osmnx in Google Colab for a while, and since this morning it doesn't work, when I go to import the library once installed it gives me the following error

here the complete process followed

!apt install gdal-bin python-gdal python3-gdal --quiet
!apt install python3-rtree --quiet
!pip install git+git://github.com/geopandas/geopandas.git --quiet
!pip install descartes --quiet


!pip install pysal --quiet
!pip install splot --quiet

import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt

import pysal
from pysal.lib  import weights
from pysal.explore import  esda
from esda.moran import Moran, Moran_Local

import splot
from splot.esda import moran_scatterplot, plot_moran, lisa_cluster

!pip install osmnx

Downloading osmnx-1.2.2-py2.py3-none-any.whl (92 kB) |████████████████████████████████| 92 kB 508 kB/s Collecting pandas>=1.4 Downloading pandas-1.5.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.2 MB) |████████████████████████████████| 12.2 MB 67.6 MB/s Collecting Rtree>=1.0 Downloading Rtree-1.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.0 MB) |████████████████████████████████| 1.0 MB 73.7 MB/s Collecting Shapely<2.0,>=1.8 Downloading Shapely-1.8.5.post1-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (2.1 MB) |████████████████████████████████| 2.1 MB 51.2 MB/s Collecting numpy>=1.22 Downloading numpy-1.24.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.3 MB) |████████████████████████████████| 17.3 MB 76.5 MB/s Requirement already satisfied: pyproj>=3.3 in /usr/local/lib/python3.8/dist-packages (from osmnx) (3.4.1) Requirement already satisfied: geopandas>=0.11 in /usr/local/lib/python3.8/dist-packages (from osmnx) (0.12.2) Collecting requests>=2.28 Downloading requests-2.28.1-py3-none-any.whl (62 kB) |████████████████████████████████| 62 kB 1.4 MB/s Requirement already satisfied: networkx>=2.8 in /usr/local/lib/python3.8/dist-packages (from osmnx) (2.8.8) Collecting matplotlib>=3.5 Downloading matplotlib-3.6.2-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (9.4 MB) |████████████████████████████████| 9.4 MB 65.5 MB/s Requirement already satisfied: fiona>=1.8 in /usr/local/lib/python3.8/dist-packages (from geopandas>=0.11->osmnx) (1.8.22) Requirement already satisfied: packaging in /usr/local/lib/python3.8/dist-packages (from geopandas>=0.11->osmnx) (21.3) Requirement already satisfied: six>=1.7 in /usr/local/lib/python3.8/dist-packages (from fiona>=1.8->geopandas>=0.11->osmnx) (1.15.0) Requirement already satisfied: certifi in /usr/local/lib/python3.8/dist-packages (from fiona>=1.8->geopandas>=0.11->osmnx) (2022.12.7) Requirement already satisfied: cligj>=0.5 in /usr/local/lib/python3.8/dist-packages (from fiona>=1.8->geopandas>=0.11->osmnx) (0.7.2) Requirement already satisfied: click-plugins>=1.0 in /usr/local/lib/python3.8/dist-packages (from fiona>=1.8->geopandas>=0.11->osmnx) (1.1.1) Requirement already satisfied: click>=4.0 in /usr/local/lib/python3.8/dist-packages (from fiona>=1.8->geopandas>=0.11->osmnx) (7.1.2) Requirement already satisfied: setuptools in /usr/local/lib/python3.8/dist-packages (from fiona>=1.8->geopandas>=0.11->osmnx) (57.4.0) Requirement already satisfied: attrs>=17 in /usr/local/lib/python3.8/dist-packages (from fiona>=1.8->geopandas>=0.11->osmnx) (22.1.0) Requirement already satisfied: munch in /usr/local/lib/python3.8/dist-packages (from fiona>=1.8->geopandas>=0.11->osmnx) (2.5.0) Requirement already satisfied: pyparsing>=2.2.1 in /usr/local/lib/python3.8/dist-packages (from matplotlib>=3.5->osmnx) (3.0.9) Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.8/dist-packages (from matplotlib>=3.5->osmnx) (1.4.4) Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.8/dist-packages (from matplotlib>=3.5->osmnx) (7.1.2) Collecting fonttools>=4.22.0 Downloading fonttools-4.38.0-py3-none-any.whl (965 kB) |████████████████████████████████| 965 kB 65.6 MB/s Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.8/dist-packages (from matplotlib>=3.5->osmnx) (2.8.2) Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.8/dist-packages (from matplotlib>=3.5->osmnx) (0.11.0) Collecting contourpy>=1.0.1 Downloading contourpy-1.0.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (295 kB) |████████████████████████████████| 295 kB 88.3 MB/s Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.8/dist-packages (from pandas>=1.4->osmnx) (2022.6) Requirement already satisfied: charset-normalizer<3,>=2 in /usr/local/lib/python3.8/dist-packages (from requests>=2.28->osmnx) (2.1.1) Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.8/dist-packages (from requests>=2.28->osmnx) (2.10) Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.8/dist-packages (from requests>=2.28->osmnx) (1.25.11) Installing collected packages: numpy, Shapely, pandas, fonttools, contourpy, Rtree, requests, matplotlib, osmnx Attempting uninstall: numpy Found existing installation: numpy 1.21.6 Uninstalling numpy-1.21.6: Successfully uninstalled numpy-1.21.6 Attempting uninstall: Shapely Found existing installation: shapely 2.0.0 Uninstalling shapely-2.0.0: Successfully uninstalled shapely-2.0.0 Attempting uninstall: pandas Found existing installation: pandas 1.3.5 Uninstalling pandas-1.3.5: Successfully uninstalled pandas-1.3.5 Attempting uninstall: Rtree Found existing installation: Rtree 0.8.3 Uninstalling Rtree-0.8.3: Successfully uninstalled Rtree-0.8.3 Attempting uninstall: requests Found existing installation: requests 2.23.0 Uninstalling requests-2.23.0: Successfully uninstalled requests-2.23.0 Attempting uninstall: matplotlib Found existing installation: matplotlib 3.2.2 Uninstalling matplotlib-3.2.2: Successfully uninstalled matplotlib-3.2.2

import osmnx

and that's when it gives me the following error:

ImportError: cannot import name 'TopologicalError' from 'shapely.geos' (/usr/local/lib/python3.8/dist-packages/shapely/geos.py)


NOTE: If your import is failing due to a missing package, you can manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the "Open Examples" button below.

Anyone knows how can I Solve it,

Thanks a lot.

  • What version of shapely is in your environment? OSMnx 1.1.1 is really old and incompatible with shapely 2.0. You'll probably have to pin shapely<2.0. – gboeing Dec 20 '22 at 15:41
  • Or you could just upgrade to, say, OSMnx 1.2.3. – gboeing Dec 20 '22 at 15:42
  • Thank you very much for your responses, I have been working with these versions for a few months and today is the first day that it does not allow me to import Tried with Shapely 1.7 also with osmnx 1.2.3 and it doesn't work either. Thanks greetings. – Santiago David Lopez Canovas Dec 20 '22 at 17:38
  • OSMnx 1.1.1 worked with Shapely 1.7.1 and there's no reason it shouldn't continue to today, as long as all the dependencies are working. It's been over a year since then, so I can't speak to it beyond that. But if you look here you can see the expected dependency versions for OSMnx 1.1.1: https://github.com/gboeing/osmnx/blob/v1.1.1/requirements.txt – gboeing Dec 20 '22 at 22:23
  • Thank you very much for the answer, I don't know what happens because I have been working with the same Colab notebook, with those versions and suddenly it doesn't work, the error happens when importing the library, it installs fine, but I can't import it. All the versions I install meet the requirements. – Santiago David Lopez Canovas Dec 21 '22 at 08:26
  • Please edit your question to provide the full error traceback you're now receiving. Also provide the installed version numbers of each OSMnx dependency. – gboeing Dec 21 '22 at 15:53
  • indicated the complete process, thanks for the help – Santiago David Lopez Canovas Dec 22 '22 at 07:18
  • And the installed version numbers of each OSMnx dependency? – gboeing Dec 22 '22 at 07:22
  • Thank you very much for trying to help me, I do this like this, before it worked for me, now it doesn't, I'm not an expert in python, and I can't give you more information. – Santiago David Lopez Canovas Dec 22 '22 at 07:50
  • don't worry, I really appreciate your help, with Jupyter Notebook it works fine for me. Thanks. – Santiago David Lopez Canovas Dec 22 '22 at 08:06

2 Answers2

0

You must install compatible versions of OSMnx's dependencies or the installation will not work properly.

  • OSMnx >= 1.3 works with Shapely >= 2.0, see here.
  • OSMnx < 1.3 works with Shapely < 2.0, see here.

Recreate your environment (and optionally explicitly specify osmnx=1.3.*) and it'll work. Make sure you follow the documented installation instructions and honor the dependency versions specified in OSMnx's requirements.txt file. See also.

gboeing
  • 5,691
  • 2
  • 15
  • 41
-1

I had the same error and rightly or wrongly I changed the import for the file osmnx/geometries.py

The import is trying to import the error class TopologicalError

this doesn't exist in shapely.geos it exists in shapely.errors so if you change the import for the file from

from shapely.geos import TopologicalError

To

from shapely.errors import TopologicalError
Nataku62
  • 33
  • 1
  • 8
  • This will only happen if you are not following the OSMnx requirements.txt pinned dependency versions. – gboeing Jan 01 '23 at 03:42