Modulenotfounderror: No Module Named 'Googlemaps'

I am a newcomer to Django python programming. Now I am working on the server side. I want to use google maps API, my view.py is like this:

from django.shortcuts import render
from django.shortcuts import HttpResponse
from googlemaps import *
# Create your views
gmaps = googlemaps.Client(key='A')

def index(request):
    if request.method=="GET":
        geocode_result = gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')
        return geocode_result

Also, I have already installed 'googlemaps' using pip. And when I import it in IDE, nothing goes wrong. But when I want to start the server to test the code, the server won't run and tells me ModuleNotFoundError: No module named 'googlemaps', I am confused that I have already downloaded it and added it in settings.py, importing in IDE also seems fine. But where I did wrong makes it fail to start the server?

2

2 Answers

Change from googlemaps import * to import googlemaps

What from googlemaps import * does is that it imports all the contents of the googlemaps module. import googlemaps imports the whole googlemaps module as a whole.

2

I got it working two different ways (assuming valid API key). Either:

from googlemaps import Client
gmaps = Client(key='A')

or:

from googlemaps import *
gmaps = Client(key='A')

Do either of these work for you?

If you're still having problems, there's a good chance it's related to your virtualenv (if using). Try running:

pip freeze

from command line and searching for the requisite library.

If you don't have an API key, you may of course want to consider using geopy. Last I checked, didn't require API key.

from geopy.geocoders import Nominatim
geolocator = Nominatim()
location = geolocator.geocode("175 5th Avenue NYC")
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest