Django:导入错误:无法导入名称 'GeoIP2'

标签 django geodjango

我正在尝试设置 geoip2根据 the instructions 为 GeoDjango .

出于某种原因,包装器没有导入函数。它在我下载数据库并在我的设置中指向它们之前工作,但由于某种原因现在我无法加载 GeoIP2 (即使我注释掉了 settings.py 中的行)。我应该如何解决这个问题?

Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 17:26:49) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import geoip2
>>>
>>> from django.contrib.gis.geoip2 import GeoIP2
Traceback (most recent call last):
  File "<console>", line 1, in <module>
ImportError: cannot import name 'GeoIP2'
>>>

编辑:我可以看到 GeoIP2函数在源文件中正确列出(我没有修改)。什么可能会阻止它加载?

我正在运行 Django 1.11.4

如果我导入 django.contrib.gis.geoip2这是__path__属性:

>>> geoip2.__path__
['C:\\Users\\Adam\\Envs\\otherlane\\lib\\site-packages\\django\\contrib\\gis\\geoip2']

最佳答案

我通过 pip 包 geoip2==2.9.0 安装它来修复

pip install geoip2==2.9.0

关于Django:导入错误:无法导入名称 'GeoIP2',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50281377/

相关文章:

javascript - GeoDjango - 外键的传单显示弹出窗口

python - 在 django 中与 elasticsearch 交互

python - django AbstractUser模型 'str'对象没有属性 '_meta'

python - 如何在保存之前修改Django表单?

django - GeoDjango 项目缺少数据库模式中的字段

python - 如何从请求中读取日文字符?

python - 为什么要使用 is_safe?

python - django get_available_name() 得到了一个意外的关键字参数 'max_length'

django - GeoDjango 模型的最佳实践