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
.
印刷品给出了错误。
If I try one of the following I get a ImportError: cannot import name GeoIP
如果我尝试以下之一,我会得到一个ImportError:无法导入名称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?
不确定这是否可以暗示某人帮助我?
1 个解决方案
#1
15
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.
看起来您没有在系统范围内安装GeoIP。 django.contrib.gis.geoip只是GeoIP库的包装器,无论如何都必须安装它。
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.
在OS X上,如果您使用自制程序,只需运行brew install geoip。如果没有,您需要确保已安装GeoIP lib,并且您的libGeoIP.dylib位于系统保存其库的任何位置。
#1
15
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.
看起来您没有在系统范围内安装GeoIP。 django.contrib.gis.geoip只是GeoIP库的包装器,无论如何都必须安装它。
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.
在OS X上,如果您使用自制程序,只需运行brew install geoip。如果没有,您需要确保已安装GeoIP lib,并且您的libGeoIP.dylib位于系统保存其库的任何位置。