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
- GDAL 通过 easy_install 安装,如下所示 '/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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你安装了
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 设置来帮助 Django 找到它。
Do you have
python-gdal
installed? It seems thatdjango.contrib.gis.gdal
only exposes theDataSource
class if it is installed. At least on Ubuntu, installingpython-django
didn't installpython-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 aGDAL_LIBRARY_PATH
setting that I think you could use to help Django find it.