django 2.x Can't work: from django.contrib.gis.geoip import HAS_GEOIP
django 2.x ModuleNotFoundError: No module named 'django.contrib.gis.geoip'
django.contrib.gis.geoip2

fast patch for this(very uggly, broke geop functionality) is:
`diff -u /usr/lib/python3.4/site-packages/tracking_/models.py /usr/lib/python3.4/site-packages/tracking/models.py --- /usr/lib/python3.4/site-packages/tracking_/models.py 2018-01-11 02:45:14.285486696 -0500 +++ /usr/lib/python3.4/site-packages/tracking/models.py 2018-01-11 02:46:14.637509051 -0500 @@ -7,9 +7,10 @@ from tracking.managers import VisitorManager, PageviewManager from tracking.settings import TRACK_USING_GEOIP
-from django.contrib.gis.geoip import HAS_GEOIP -if HAS_GEOIP:
- from django.contrib.gis.geoip import GeoIP, GeoIPException +#from django.contrib.gis.geoip2 import HAS_GEOIP +HAS_GEOIP=False +#if HAS_GEOIP: +# from django.contrib.gis.geoip2 import GeoIP, GeoIPException
GEOIP_CACHE_TYPE = getattr(settings, 'GEOIP_CACHE_TYPE', 4)`
Facing the same problem while migrating to Django-2
File "
Looking for any updated!
geoip2 works just fine.
from django.contrib.gis.geoip2 import GeoIP2
Make sure to have installed the python library, you can do pip install geoip2 and set the path to the dataset in your settings.py correctly.
Django docs explains the steps clearly.
Yes, geoip2 works just fine.
REFER:
https://docs.djangoproject.com/en/2.0/ref/contrib/gis/geoip2/
Step by step guide:
-
Install requests library (if needed)
pip install requests -
Install geoip2
pip install geoip2 -
For working geoip2 faster based on external C library, you can install libmaxminddb0
sudo add-apt-repository ppa:maxmind/ppasudo apt updatesudo apt install libmaxminddb0 libmaxminddb-dev mmdb-bin
4.Download GeoLite2 databases (GeoLite2 City and GeoLite2 Country) only in binary format from here: https://dev.maxmind.com/geoip/geoip2/geolite2/
- Next unzip both downloaded file and put both(GeoLite2-City.mmdb and GeoLite2-Country.mmdb) file in geoip2 folder made into your django projects root folder.
For example, My root folder looks like:
_src_:
_geoip2_:
_GeoLite2-City.mmdb_
_GeoLite2-Country.mmdb_
-
Now add GEOIP_PATH into your settings.py file:
GEOIP_PATH = os.path.join(BASE_DIR, 'geoip2') -
Now you'r all ready to go.
django2.0
from django.contrib.gis.geoip import HAS_GEOIP ModuleNotFoundError: No module named 'django.contrib.gis.geoip'
I add those to settings: GEOIP_PATH = os.path.join(BASE_DIR, 'geoip2')
and download GeoLite2 databases (GeoLite2 City and GeoLite2 Country) only in binary format from here:https://dev.maxmind.com/geoip/geoip2/geolite2/ Next unzip both downloaded file and put both(GeoLite2-City.mmdb and GeoLite2-Country.mmdb) file in geoip2 folder made into my django projects root folder.
I just not use GEOP. While i should do additional configuration, check i have valid dbs for this simple module? From my point of view it should not rise exception if it can't load module which not states in package dependencies.
django.contrib.gis.geoip was deprecated and upgraded to django.contrib.gis.geoip2 so this needs a fix and pull request
This issue should be resolved with https://github.com/bruth/django-tracking2/pull/73.