我正在使用Django 1.5.5。
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: 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
位于系统保留其库的任何位置。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句