Reputation: 51
I cannot import GeoIP in django. I searched and tested this error two days, but still could not know problem.
Surely, I installed GeoDjango. I'm on MacOS 10.8
following is log by tested by django shell
from django.contrib.gis import geoip
module 'django.contrib.gis.geoip' from '/Library/Python/2.7/site-packages/django/contrib/gis/geoip/__init__.pyc'
it works. even I could find geoip class at Library/Python/2.7/site-packages/django/contrib/gis/geoip/base.py
from django.contrib.gis.geoip import geoip
Traceback (most recent call last): File "", line 1, in ImportError: cannot import name geoip
I also add django.contrib.gis to setting.py. Even I could find geoip class at eclipse shortcut.
anyway, I tested one more thing in django shell.
from django.contrib.gis.geoip.base import GeoIP
Traceback (most recent call last): File "", line 1, in File "/Library/Python/2.7/site-packages/django/contrib/gis/geoip/base.py", line 6, in from django.contrib.gis.geoip.libgeoip import GEOIP_SETTINGS File "/Library/Python/2.7/site-packages/django/contrib/gis/geoip/libgeoip.py", line 22, in if lib_path is None: raise GeoIPException('Could not find the GeoIP library (tried "%s"). ' NameError: name 'GeoIPException' is not defined
What I missing?
Is there any way to test my error?
Upvotes: 1
Views: 3912
Reputation: 1
The error is caused by moving the virtual environment folder.
The solution is to create the environment again and reinstall the pygeoip library.
Upvotes: 0
Reputation: 196
Previously i was facing this issue : from django.contrib.gis.geoip import GeoIP ImportError: cannot import name GeoIP
which is solved when i install this package.
yum install GeoIP-devel -y
Upvotes: 1
Reputation: 17659
It appears you need to install a C library in order to use GeoIP.
Here is a snippet from the file that is throwing that error.
# The shared library for the GeoIP C API. May be downloaded
# from http://www.maxmind.com/download/geoip/api/c/
if lib_path:
lib_name = None
else:
# TODO: Is this really the library name for Windows?
lib_name = 'GeoIP'
Once you have it installed somewhere you need to reference it in your settings.py
GEOIP_LIBRARY_PATH = '/whatever'
The library was trying to tell you this, but it seems that there is a bug that prevents it from raising the correct error. https://github.com/django/django/pull/103
Upvotes: 1