2012-10-06 139 views
1

我無法在django中導入GeoIP。我搜索並測試了這個錯誤兩天,但仍然不知道問題。Python/django:無法導入GeoIP

當然,我安裝了GeoDjango。我在Mac OS 10.8

以下是日誌由Django的測試殼

1>>from django.contrib.gis import geoip

2>>module 'django.contrib.gis.geoip' from '/Library/Python/2.7/site-packages/django/contrib/gis/geoip/init.pyc'>

它的工作原理。即使我能找到的圖書館/ Python的/ 2.7 geoip的類/站點包/ Django的/的contrib/GIS/geoip的/ base.py


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


我還加django.contrib.gis到setting.py。即使我可以在eclipse快捷方式中找到geoip類。無論如何,我在django shell中測試了一件更多的東西。

from django.contrib.gis.geoip.base import GeoIP

Traceback (most recent call last): File "", line 1, in File "/Library/Python/2.7/site-packages/django/contrib/gis/geoip/base.py", line 6, in from django.contrib.gis.geoip.libgeoip import GEOIP_SETTINGS File "/Library/Python/2.7/site-packages/django/contrib/gis/geoip/libgeoip.py", line 22, in if lib_path is None: raise GeoIPException('Could not find the GeoIP library (tried "%s"). ' NameError: name 'GeoIPException' is not defined

我缺少什麼?

有什麼方法可以測試我的錯誤嗎?

回答

1

看來您需要安裝C庫才能使用GeoIP。

以下是拋出該錯誤的文件片段。

# The shared library for the GeoIP C API. May be downloaded 
# from http://www.maxmind.com/download/geoip/api/c/ 
if lib_path: 
    lib_name = None 
else: 
    # TODO: Is this really the library name for Windows? 
    lib_name = 'GeoIP' 

一旦你有它的地方安裝你需要引用它在你的settings.py

GEOIP_LIBRARY_PATH = '/whatever' 

庫試圖告訴你這一點,但它似乎沒有阻止它的錯誤從提高正確的錯誤。 https://github.com/django/django/pull/103

0

以前我面臨這個問題:從django.contrib.gis.geoip進口GeoIP的導入錯誤:無法導入名稱的GeoIP

當我安裝該軟件包,解決。

yum install GeoIP-devel -y