本文介绍了无法在Django中导入GeoIP模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Django 1.5.5。

I'm using Django 1.5.5.

settings.py:

settings.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:不能导入名称GeoIP

If I try one of the following I get a 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 模块。

Generally it looks like geoip does not contain a GeoIP module.

另外,如果我在终端中打开 python

Also if I open python in the terminal:

>>> from django.contrib.gis.geoip import GeoIP
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name GeoIP






一些更多的信息,如果我打印:


Some more info, if I print:

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

不知道是否可以提示有人帮助我?

Not sure if that can be a hint for someone to help me?

推荐答案

看起来你的系统范围内没有安装GeoIP。 django.contrib.gis.geoip 只是围绕GeoIP库的一个包装器,而且必须安装。

It looks like you don't have GeoIP installed system-wide. django.contrib.gis.geoip is just a wrapper around the GeoIP library, and it must be installed regardless.

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

On OS X, if you use homebrew, just run brew install geoip. If not, you need to make sure the GeoIP lib is installed, and that you have libGeoIP.dylib located wherever your system keeps its libraries.

这篇关于无法在Django中导入GeoIP模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-27 11:35