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

Question:

I am using VS and I am trying to run geopy, I installed all the prerequisites and get this error
"ModuleNotFoundError: No module named ‘geopy.geocoders’; ‘geopy’ is not a package"

from geopy.geocoders import Nominatim

geolocator = Nominatim(user_agent="http")
location = geolocator.geocode("175 5th Avenue NYC")
print(location.address)
print((location.latitude, location.longitude))
print(location.raw)

What am I missing?

Asked By: IguanaBot

||

Answers:

I suspect the problem lies in you installing the geopy package in wrong version of python (The one that comes pre-installed in AppDataLocalMicrosoftWindowsAppspython.exe is not full install). Grab a version of python (Either anaconda or vanilla python from python website). Let it install in default location, and then point VS code version of python that comes pre-installed with windows. Install geopypackage thorugh pip install geopy, either with VS, or through cmd with conda or pip. This should fix your problem.

Answered By: Psychotechnopath

This error: ModuleNotFoundError: No module named 'geopy.geocoders'; 'geopy' is not a package may also occur if you have named the main program file you created as geopy.py and try to run it as python geopy.py or another file has the name geopy.py in the same folder from which you run your program. Python will consider your program file as a module and try to find something in it that is naturally not in it. About where the Python is looking for modules, see sys.path.

In this case, rename your program file so that its name does not equal with the name of the imported module.

Answered By: kirogasa
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.