Home > Software engineering >  Struggling with geopy install. ModuleNotFoundError: No module named 'geopy.geocoders'
Struggling with geopy install. ModuleNotFoundError: No module named 'geopy.geocoders'

Time:01-11

I ran pip install geopy and it seemed to install ok, but I couldn't run the following script.

from geopy.geocoders import Nominatim
geolocator = Nominatim(user_agent="ryan_data")
location = geolocator.geocode("175 5th Avenue NYC")
print(location.address)

That script gives me this.

Traceback (most recent call last):

  File "C:\Users\ryans\AppData\Local\Temp\ipykernel_19160\137417210.py", line 1, in <module>
    from geopy.geocoders import Nominatim

  File "C:\Users\ryans\geopy.py", line 3, in <module>
    from geopy.geocoders import Nominatim

ModuleNotFoundError: No module named 'geopy.geocoders'; 'geopy' is not a package

I also tried the following three lines to get geopy installed; none worked.

conda install -c conda-forge geopy
conda install -c conda-forge geopy=2.3.0
conda install -c conda-forge geopandas=0.10

The geopy package works fine on another computer that I use, but it doesn't seem to install on the laptop that I am using now. Has anyone encountered this issue before? Any idea how I can get this package installed?

CodePudding user response:

Looking at the error traceback, you have a file named geopy.py. Your script is attempting to load that file instead of the geopy package.

Rename the geopy.py file to something else.

  • Related