繁体   English   中英

不能在python中导入gdal?

[英]can't import gdal in python?

我在 Ubuntu Jaunty 上安装并运行了gdal ,但我无法运行gdal2tiles因为我收到错误消息:

Traceback (most recent call last):
  File "/usr/local/bin/gdal2tiles.py", line 42, in <module>
    import gdal
ImportError: No module named gdal

当我打开 python 并输入import gdal我得到了同样的错误。

我已经set LD_LIBRARY_PATH (没有空格!)设置为/usr/local/lib但它似乎没有任何区别。

看起来 Python 找不到gdal 任何人都可以帮忙吗?

谢谢!

Ith似乎是“ Python路径 ”问题。 在定义的路径中查找Python库。 尝试

import sys
sys.path

如果gdal.py和相关文件所在的目录不在此列表中,则Python无法找到它。 这是针对“诊断”部分的。 要解决这种情况,您有几种选择...它们全部取决于了解Python用于构建此路径的规则。

  • 可以更改PYTHONPATH环境变量以包括所需的路径
  • 可以从所需库所在的目录中启动Python。
  • 可以使用sys.path.append(“ / SomePath / To / MyStuff”)动态更改sys.path

在“官方” Python文档中,我唯一看到过关于sys.path生成规则的地方是在教程的 6.1.2节中。
摘抄:

modules are searched in the list of directories given by the variable sys.path
which is initialized from the directory containing the input script (or the 
current directory), PYTHONPATH and the installation- dependent default. This
allows Python programs that know what they’re doing to modify or replace the
module search path. Note that because the directory containing the script being
run is on the search path, it is important that the script not have the same name
as a standard module, or Python will attempt to load the script as a module when
that module is imported. This will generally be an error. See section
Standard Modules for more information.

这里是一个链接,该链接教您如何安装和使用Python + GDAL,OGR和其他工具。

我希望它有用。

http://www.gis.usu.edu/~chrisg/python/2009/

您可能还需要查看专用于与Python绑定的GDAL Wiki- GdalOgrInPython ,其中讨论了Linux和Windows平台上的安装和用法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM