gpt4 book ai didi

python - 无法在 Django 中导入 GeoIP 模块

转载 作者:太空狗 更新时间:2023-10-29 20:38:48 25 4
gpt4 key购买 nike

我正在使用 Django 1.5.5。

设置.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'>

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

最佳答案

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

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

关于python - 无法在 Django 中导入 GeoIP 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20033552/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com