我用的是Django 1.5.5。
设置.py:
GEOIP_PATH = os.path.join(PROJECT_DIR, 'geoIP')
INSTALLED_APPS = (..,'django.contrib.gis',..)
视图.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
。相关问题 更多 >
编程相关推荐