2012-12-01 60 views
0

我gettinh這個錯誤與djnago無法導入libgdal與Python的Django

>>> import django.contrib.gis.gdal 
>>> print django.contrib.gis.gdal.libgdal.gdal_full_version() 
Traceback (most recent call last): 
    File "<console>", line 1, in <module> 
AttributeError: 'module' object has no attribute 'libgdal' 
>>> ^C 
KeyboardInterrupt 

,我有根據本

$ locate libgdal 

/usr/local/lib/python2.7/site-packages/django/contrib/gis/gdal/libgdal.py 
/usr/local/lib/python2.7/site-packages/django/contrib/gis/gdal/libgdal.pyc 
/usr/local/lib/python2.7/site-packages/django/contrib/gis/gdal/libgdal.pyo 

回答

2

導入在Python包並不一定自動導入任何子封裝/模塊它。當您執行import django.contrib.gis.gdal時,它在gdal目錄中運行__init__.py;它取決於該文件,不管它是否通過import libgdal以便通過gdal可用。在這種特殊情況下,gdal進口(等等)從libgdalgdal_full_version功能到其本身,而不是libgdal作爲一個整體,所以你可以這樣做:

>>> import django.contrib.gis.gdal 
>>> print django.contrib.gis.gdal.gdal_full_version() 
GDAL 1.6.3, released 2009/11/19 

或將明確就函數實際上是定義在那裏,你可以這樣做:

>>> import django.contrib.gis.gdal.libgdal 
>>> print django.contrib.gis.gdal.libgdal.gdal_full_version() 
GDAL 1.6.3, released 2009/11/19 
+0

感謝哥們,那工作 – user825904