Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to install the MaxMind GeoIP C library, so that I can use GeoIP as part of Django. I'm working on MacOS.

I've downloaded GeoIP-1.4.8.tar.gz from here and run:

./configure
make
make check
make install

without any problems. I've also downloaded GeoIP.dat.gz and GeoLiteCity.dat.gz, unzipped them and put them in a local directory.

Then I've set the following paths in my settings.py:

GEOIP_PATH = 'path_to_dat_files'
GEOIP_LIBRARY_PATH = 'path_to_c_files'

Now I'm trying to run python manage.py migrate (which has a reference to GeoIP in a project I'm using), but I'm still getting this error:

from django.contrib.gis.utils import GeoIP
ImportError: cannot import name GeoIP

Any ideas? Thanks.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

I just follow the same procedure and found nothing wrong

./configure
make
make check
make install

and put the geo unzip-ed database in django project's root dir, add the following to settings.py:

GEOIP_PATH = "./"

here is what I run and got:

% python manage.py shell
>>> from django.contrib.gis.utils import GeoIP
>>> g = GeoIP()
>>> g.country('google.com')
{'country_name': 'United States', 'country_code': 'US'}
>>>>
share|improve this answer
add comment

After compiling it should print the library path:


Libraries have been installed in: /usr/local/lib

Set the path to the dylib file:

GEOIP_LIBRARY_PATH = '/usr/local/lib/libGeoIP.dylib'
GEOIP_PATH = GEOIP_DATA_FILE
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.