Diolor
Diolor

Reputation: 13450

Cannot import GeoIP module in Django

I'm using Django 1.5.5.

settings.py:

GEOIP_PATH = os.path.join(PROJECT_DIR,  'geoIP')
INSTALLED_APPS = (..,'django.contrib.gis',..)

views.py:

from django.contrib.gis import geoip
print geoip.HAS_GEOIP

the print gives false.

If I try one of the following I get a ImportError: cannot import name GeoIP

from django.contrib.gis.utils import GeoIP #this one is deprecated whatsoever
from django.contrib.gis.utils.geoip import GeoIP #this one is deprecated whatsoever
from django.contrib.gis.geoip import GeoIP

Generally it looks like geoip does not contain a GeoIP module.

Also if I open python in the terminal:

>>> from django.contrib.gis.geoip import GeoIP
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name GeoIP

Some more info, if I print:

from django.contrib.gis import geoip
print geoip

I get:

<module 'django.contrib.gis.geoip' from '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/contrib/gis/geoip/__init__.pyc'>

Not sure if that can be a hint for someone to help me?

Upvotes: 8

Views: 13178

Answers (1)

Yuval Adam
Yuval Adam

Reputation: 165182

It looks like you don't have GeoIP installed system-wide. django.contrib.gis.geoip is just a wrapper around the GeoIP library, and it must be installed regardless.

On OS X, if you use homebrew, just run brew install geoip. If not, you need to make sure the GeoIP lib is installed, and that you have libGeoIP.dylib located wherever your system keeps its libraries.

Upvotes: 19

Related Questions