Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mantiswang opened this issue Jan 7, 2018 · 8 comments
Open

Comments

@mantiswang
Copy link

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

@arheops
Copy link

arheops commented Jan 11, 2018

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

@hubert10
Copy link

hubert10 commented Mar 14, 2018

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!

@yusufoguntola
Copy link

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.

@milankathiriya
Copy link

milankathiriya commented Jul 16, 2018

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.

@insseek
Copy link

insseek commented Jan 23, 2019

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.

@arheops
Copy link

arheops commented Jan 23, 2019

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.

@rjmoggach
Copy link

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

@tpeaton
Copy link
Contributor

tpeaton commented Jan 29, 2019

This issue should be resolved with #73.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants