python 中的导入问题

发布于 2024-10-23 22:19:36 字数 647 浏览 4 评论 0原文

我是 python 的超级新手,我刚刚部署一个用 python 完成的开源应用程序,我得到一个:

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

但是,这很好:

import django.contrib.gis.gdal

我当前的环境设置是:

  1. Linux
  2. Python 2.7 安装在 /opt/python
  3. GDAL 通过 easy_install 安装,如下所示 '/opt/python /bin/easy_install GDAL'
  4. 执行 #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:

  1. Linux
  2. Python 2.7 installed in /opt/python
  3. GDAL installed via easy_install like so '/opt/python/bin/easy_install GDAL'
  4. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嘿咻 2024-10-30 22:19:36

你安装了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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文