[英]Cannot import GeoIP module in Django
I'm using Django 1.5.5. 我正在使用Django 1.5.5。
settings.py: settings.py:
GEOIP_PATH = os.path.join(PROJECT_DIR, 'geoIP')
INSTALLED_APPS = (..,'django.contrib.gis',..)
views.py: views.py:
from django.contrib.gis import geoip
print geoip.HAS_GEOIP
the print gives false
. 印刷品为
false
。
If I try one of the following I get a ImportError: cannot import name GeoIP
如果尝试以下操作之一,
ImportError: cannot import name GeoIP
收到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
Generally it looks like geoip
does not contain a GeoIP
module. 通常,看起来
geoip
不包含GeoIP
模块。
Also if I open python
in the terminal: 另外,如果我在终端中打开
python
:
>>> 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
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'>
Not sure if that can be a hint for someone to help me? 不知道这是否可以暗示有人帮助我?
It looks like you don't have GeoIP installed system-wide. 看来您没有在系统范围内安装GeoIP。
django.contrib.gis.geoip
is just a wrapper around the GeoIP library, and it must be installed regardless. django.contrib.gis.geoip
只是GeoIP库的包装,无论如何都必须安装。
On OS X, if you use homebrew, just run brew install geoip
. 在OS X上,如果您使用自制软件,只需运行
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. 如果没有,则需要确保已安装GeoIP库,并且必须在系统保留其库的任何位置找到
libGeoIP.dylib
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.