Struggling with geopy install. ModuleNotFoundError: No module named 'geopy.geocoders'

Question:

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:UsersryansAppDataLocalTempipykernel_19160137417210.py", line 1, in <module>
    from geopy.geocoders import Nominatim

  File "C:Usersryansgeopy.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?

Asked By: ASH

||

Answers:

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.

Answered By: jkr
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.