我正在使用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
打印件提供false
。
如果我尝试以下其中一项,我会得到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
通常看起来geoip
不包含GeoIP
模块。
如果我在终端中打开python
:
>>> from django.contrib.gis.geoip import GeoIP
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name GeoIP
如果我打印了更多信息:
from django.contrib.gis import geoip
print geoip
我明白了:
<module 'django.contrib.gis.geoip' from '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/contrib/gis/geoip/__init__.pyc'>
不确定这是否可以暗示有人帮助我?
答案 0 :(得分:17)
您似乎没有在系统范围内安装GeoIP。 django.contrib.gis.geoip
只是GeoIP库的包装器,无论如何都必须安装。
在OS X上,如果您使用自制程序,只需运行brew install geoip
即可。如果没有,您需要确保已安装GeoIP lib,并确保libGeoIP.dylib
位于系统保存其库的任何位置。