django-tracking2 icon indicating copy to clipboard operation
django-tracking2 copied to clipboard

django 2.x Can't work: from django.contrib.gis.geoip import HAS_GEOIP

Open mantiswang opened this issue 8 years ago • 8 comments

django 2.x ModuleNotFoundError: No module named 'django.contrib.gis.geoip' django.contrib.gis.geoip2 535f86e4-2787-41ab-8322-f9b721f13113

mantiswang avatar Jan 07 '18 03:01 mantiswang

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)`

arheops avatar Jan 11 '18 07:01 arheops

Facing the same problem while migrating to Django-2

File "", line 958, in _find_and_load_unlocked File "", line 673, in _load_unlocked File "", line 665, in exec_module File "", line 222, in _call_with_frames_removed File "/Test/App/django_2/lib/python3.5/site-packages/tracking/models.py", line 10, in from django.contrib.gis.geoip import HAS_GEOIP ImportError: No module named 'django.contrib.gis.geoip'

Looking for any updated!

hubert10 avatar Mar 14 '18 10:03 hubert10

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.

yusufoguntola avatar Apr 02 '18 07:04 yusufoguntola

Yes, geoip2 works just fine.

REFER:

https://docs.djangoproject.com/en/2.0/ref/contrib/gis/geoip2/

Step by step guide:

  1. Install requests library (if needed) pip install requests

  2. Install geoip2 pip install geoip2

  3. For working geoip2 faster based on external C library, you can install libmaxminddb0 sudo add-apt-repository ppa:maxmind/ppa sudo apt update sudo 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/

  1. 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_
  1. Now add GEOIP_PATH into your settings.py file: GEOIP_PATH = os.path.join(BASE_DIR, 'geoip2')

  2. Now you'r all ready to go.

milankathiriya avatar Jul 16 '18 08:07 milankathiriya

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.

insseek avatar Jan 23 '19 04:01 insseek

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.

arheops avatar Jan 23 '19 05:01 arheops

django.contrib.gis.geoip was deprecated and upgraded to django.contrib.gis.geoip2 so this needs a fix and pull request

rjmoggach avatar Jan 26 '19 04:01 rjmoggach

This issue should be resolved with https://github.com/bruth/django-tracking2/pull/73.

tpeaton avatar Jan 29 '19 16:01 tpeaton