我已经用brew install geoip安装了GeoIP C库,并且成功了。我也是通过pip install geoip安装的,但是当我试图从Django导入GeoIP时,我得到了以下错误:
>>> from django.contrib.gis.geoip import GeoIP
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: cannot import name 'GeoIP'虽然我知道安装了GeoIP库,但我已经找到了this问题,但它没有回答我的问题。
发布于 2020-07-15 20:53:54
在我的例子中,需要做的是:
brew install geoip然后,检查Homebrew将把GeoIP文件放在哪里。例如,我这一端的输出是:
==> Pouring geoip-1.6.12.mojave.bottle.1.tar.gz
? /usr/local/Cellar/geoip/1.6.12: 18 files, 553.0KB因此,在本地设置中设置它,以便Django的GeoIP可以找到它:
GEOIP_PATH = '/usr/local/Cellar/geoip/1.6.12/'根据https://docs.djangoproject.com/en/dev/ref/contrib/gis/geoip2/#std:setting-GEOIP_PATH。在此之后,导入错误就消失了。
https://stackoverflow.com/questions/38536071
复制相似问题