[Django]-Django: ImportError: cannot import name 'GeoIP2'

4👍

This module is Deprecated since version 1.9 in favor of django.contrib.gis.geoip2, which supports IPv6 and the GeoLite2 database format.

If you have a django < 1.9, use instead

from django.contrib.gis.geoip import GeoIP

7👍

I fixed by installing it through pip package geoip2==2.9.0

pip install geoip2==2.9.0

2👍

just run the command pip install geoip2 then it will work fine…

1👍

Double check your GEOIP_PATH. And my I remind you that Windows requires back slashes not forward slashes.

1👍

I was also facing the same error and couldn’t resolve it after multiple attempts.
Since it was working on one of my system, I found one difference, When you install geoip2 via pip it also installs maxminddb. The system on which it was working, maxminddb version was 1.5.4 and the one on which it was not working it was maxminddb==2.0.0
so finally I did
pip install maxminddb==1.5.4
and it worked

0👍

You can handle it this way

from geoip2 import geolite2

Leave a comment