无法在Django中导入GeoIP模块

Dio*_*lor 8 python django

我正在使用Django 1.5.5.

settings.py:

GEOIP_PATH = os.path.join(PROJECT_DIR,  'geoIP')
INSTALLED_APPS = (..,'django.contrib.gis',..)
Run Code Online (Sandbox Code Playgroud)

views.py:

from django.contrib.gis import geoip
print geoip.HAS_GEOIP
Run Code Online (Sandbox Code Playgroud)

印刷品给出了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
Run Code Online (Sandbox Code Playgroud)

通常它看起来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
Run Code Online (Sandbox Code Playgroud)

更多信息,如果我打印:

from django.contrib.gis import geoip
print geoip
Run Code Online (Sandbox Code Playgroud)

我明白了:

<module 'django.contrib.gis.geoip' from '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/contrib/gis/geoip/__init__.pyc'>
Run Code Online (Sandbox Code Playgroud)

不确定这是否可以暗示某人帮助我?

Yuv*_*dam 19

看起来您没有在系统范围内安装GeoIP.django.contrib.gis.geoip只是GeoIP库的包装器,必须安装它.

在OS X上,如果你使用自制程序,只需运行即可brew install geoip.如果没有,您需要确保已安装GeoIP lib,并且您已libGeoIP.dylib找到系统保存其库的位置.

  • 请使用 geopi2,因为 geoip 已被弃用 (2认同)