在python中导入困境(import woes in python)

我是python上的新手,我只是部署一个在python中完成的开源应用程序,我得到一个:

ImportError: cannot import name DataSource on from django.contrib.gis.gdal import DataSource

但是,这很好:

import django.contrib.gis.gdal

我目前的环境设置是:

Linux的 Python 2.7安装在/ opt / python中 通过easy_install安装GDAL,如'/ opt / python / bin / easy_install GDAL' 做#3看起来好像已经安装在这里:'/ opt / python / lib / python2.7 / site-packages / GDAL-1.7.1-py2.7.egg-info'

有人可以指导我吗?

如果我可以import django.contribs.gis.gdal ,为什么无法导入DataSource ? 我假设DataSource也是GDAL库的一部分?

I'm super new on python and i am just deploying an open source app that was done in python and I'm getting a:

ImportError: cannot import name DataSource on from django.contrib.gis.gdal import DataSource

However, this is just fine:

import django.contrib.gis.gdal

My current environment setup is:

Linux Python 2.7 installed in /opt/python GDAL installed via easy_install like so '/opt/python/bin/easy_install GDAL' Doing #3 looks like it got installed here: '/opt/python/lib/python2.7/site-packages/GDAL-1.7.1-py2.7.egg-info'

Could someone guide me here please?

If i could do import django.contribs.gis.gdal, how come DataSource cannot be imported? I assume DataSource is also part of the GDAL library?

最满意答案

你安装了python-gdal吗? 似乎django.contrib.gis.gdal 公开DataSource类(如果已安装)。 至少在Ubuntu上,安装python-django默认情况下没有安装python-gdal 。

编辑:如下面的评论中所述,你确实安装了它,但负责找到它的模块, django/contrib/gis/gdal/libgdal.py没有找到它。 如果您查看该模块的源代码(例如http://code.djangoproject.com/browser/django/branches/gis/django/contrib/gis/gdal/libgdal.py?rev=8012 ), GDAL_LIBRARY_PATH出现GDAL_LIBRARY_PATH设置我认为你可以用来帮助Django找到它。

Do you have python-gdal installed? It seems that django.contrib.gis.gdal only exposes the DataSource class if it is installed. At least on Ubuntu, installing python-django didn't install python-gdal by default.

EDIT: as noted in the comments below, you did have it installed, but the module responsible for locating it, django/contrib/gis/gdal/libgdal.py did not find it. If you peek in the source for that module (e.g. http://code.djangoproject.com/browser/django/branches/gis/django/contrib/gis/gdal/libgdal.py?rev=8012), there's a GDAL_LIBRARY_PATH setting that I think you could use to help Django find it.

在python中导入困境(import woes in python)

我是python上的新手,我只是部署一个在python中完成的开源应用程序,我得到一个:

ImportError: cannot import name DataSource on from django.contrib.gis.gdal import DataSource

但是,这很好:

import django.contrib.gis.gdal

我目前的环境设置是:

Linux的 Python 2.7安装在/ opt / python中 通过easy_install安装GDAL,如'/ opt / python / bin / easy_install GDAL' 做#3看起来好像已经安装在这里:'/ opt / python / lib / python2.7 / site-packages / GDAL-1.7.1-py2.7.egg-info'

有人可以指导我吗?

如果我可以import django.contribs.gis.gdal ,为什么无法导入DataSource ? 我假设DataSource也是GDAL库的一部分?

I'm super new on python and i am just deploying an open source app that was done in python and I'm getting a:

ImportError: cannot import name DataSource on from django.contrib.gis.gdal import DataSource

However, this is just fine:

import django.contrib.gis.gdal

My current environment setup is:

Linux Python 2.7 installed in /opt/python GDAL installed via easy_install like so '/opt/python/bin/easy_install GDAL' Doing #3 looks like it got installed here: '/opt/python/lib/python2.7/site-packages/GDAL-1.7.1-py2.7.egg-info'

Could someone guide me here please?

If i could do import django.contribs.gis.gdal, how come DataSource cannot be imported? I assume DataSource is also part of the GDAL library?

最满意答案

你安装了python-gdal吗? 似乎django.contrib.gis.gdal 公开DataSource类(如果已安装)。 至少在Ubuntu上,安装python-django默认情况下没有安装python-gdal 。

编辑:如下面的评论中所述,你确实安装了它,但负责找到它的模块, django/contrib/gis/gdal/libgdal.py没有找到它。 如果您查看该模块的源代码(例如http://code.djangoproject.com/browser/django/branches/gis/django/contrib/gis/gdal/libgdal.py?rev=8012 ), GDAL_LIBRARY_PATH出现GDAL_LIBRARY_PATH设置我认为你可以用来帮助Django找到它。

Do you have python-gdal installed? It seems that django.contrib.gis.gdal only exposes the DataSource class if it is installed. At least on Ubuntu, installing python-django didn't install python-gdal by default.

EDIT: as noted in the comments below, you did have it installed, but the module responsible for locating it, django/contrib/gis/gdal/libgdal.py did not find it. If you peek in the source for that module (e.g. http://code.djangoproject.com/browser/django/branches/gis/django/contrib/gis/gdal/libgdal.py?rev=8012), there's a GDAL_LIBRARY_PATH setting that I think you could use to help Django find it.