Unable to import GeoIP module in Django

I am 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 

print gives false .

If I try to do one of the following, I get 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 

Typically, it looks like this: 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 

Additional information 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 this could be a clue for someone who can help me?

+7
python django
source share
1 answer

It seems that you do not have GeoIP installed on the system. django.contrib.gis.geoip is just the shell of the GeoIP library, and it must be installed independently.

On OS X, if you are using homegrown, just run brew install geoip . If not, you need to make sure that GeoIP lib is installed, and that you have libGeoIP.dylib , where your system stores its libraries.

+15
source share

All Articles