无法在 Django 中导入 GeoIP 模块

2023-11-25

我正在使用 Django 1.5.5。

设置.py:

GEOIP_PATH = os.path.join(PROJECT_DIR,  'geoIP')
INSTALLED_APPS = (..,'django.contrib.gis',..)

视图.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 module.

另外如果我打开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

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'>

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


您似乎没有在系统范围内安装 GeoIP。django.contrib.gis.geoip只是 GeoIP 库的包装,无论如何都必须安装它。

在 OS X 上,如果您使用自制软件,只需运行brew install geoip。如果没有,您需要确保安装了 GeoIP 库,并且您有libGeoIP.dylib位于系统保存其库的任何位置。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法在 Django 中导入 GeoIP 模块 的相关文章

随机推荐