不能在python中导入gdal吗?

时间:2023-01-17 17:15:11

I have gdal installed and running on Ubuntu Jaunty but I can't run gdal2tiles because I get the error:

我已经在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

When I open python and type import gdal I get the same error.

当我打开python并输入import gdal时,我也会得到同样的错误。

I've set LD_LIBRARY_PATH (without spaces!) to /usr/local/lib but it doesn't seem to have made any difference.

我已经将LD_LIBRARY_PATH(没有空格!)设置为/usr/local/lib,但这似乎没有什么区别。

Looks like Python can't find gdal. Can anyone help?

看起来Python找不到gdal。谁能帮忙吗?

Thanks!

谢谢!

3 个解决方案

#1


14  

Ith seems to be a "Python Path" issue.  Python libraries are looked-up within a defined path. Try

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

import sys
sys.path

If the directory where the gdal.py and related files is not in this list, then Python cannot find it. That's for the "diagnostics" part. To fix the situation, you have several options... They all hinge on knowing the rules which Python uses to build this path.

如果目录中的gdal。py和相关文件不在这个列表中,因此Python无法找到它。这是“诊断”部分的内容。为了解决这个问题,你有几个选择……它们都依赖于了解Python用来构建此路径的规则。

  • The PYTHONPATH environement variable can be altered to include the desired path
  • 可以更改PYTHONPATH环境变量以包含所需的路径
  • Python can be started from the directory where the desired library resides.
  • 可以从所需库所在的目录启动Python。
  • sys.path can be dynamically altered, with sys.path.append("/SomePath/To/MyStuff")
  • sys。path.append(“/SomePath/To/MyStuff”)

The only place where I've seen the rules pertaining to the building of sys.path formerly described, within the "official" Python documentation, is in the tutorial, at section 6.1.2
Excerpt:

我只在一个地方见过关于建立系统的规则。在“官方”Python文档中,前面描述的路径在教程中,在第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.

#2


5  

Here is a link that teaches how to install and use Python + GDAL, OGR and other tools.

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

I hope its useful.

我希望它有用。

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

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

#3


1  

You may also want to check GDAL Wiki dedicated to the bindings to Python - GdalOgrInPython where the installation and usage on Linux and Windows platforms is discussed.

您还可能想要检查GDAL Wiki专用于Python - GdalOgrInPython的绑定,其中讨论了Linux和Windows平台上的安装和使用情况。

#1


14  

Ith seems to be a "Python Path" issue.  Python libraries are looked-up within a defined path. Try

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

import sys
sys.path

If the directory where the gdal.py and related files is not in this list, then Python cannot find it. That's for the "diagnostics" part. To fix the situation, you have several options... They all hinge on knowing the rules which Python uses to build this path.

如果目录中的gdal。py和相关文件不在这个列表中,因此Python无法找到它。这是“诊断”部分的内容。为了解决这个问题,你有几个选择……它们都依赖于了解Python用来构建此路径的规则。

  • The PYTHONPATH environement variable can be altered to include the desired path
  • 可以更改PYTHONPATH环境变量以包含所需的路径
  • Python can be started from the directory where the desired library resides.
  • 可以从所需库所在的目录启动Python。
  • sys.path can be dynamically altered, with sys.path.append("/SomePath/To/MyStuff")
  • sys。path.append(“/SomePath/To/MyStuff”)

The only place where I've seen the rules pertaining to the building of sys.path formerly described, within the "official" Python documentation, is in the tutorial, at section 6.1.2
Excerpt:

我只在一个地方见过关于建立系统的规则。在“官方”Python文档中,前面描述的路径在教程中,在第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.

#2


5  

Here is a link that teaches how to install and use Python + GDAL, OGR and other tools.

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

I hope its useful.

我希望它有用。

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

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

#3


1  

You may also want to check GDAL Wiki dedicated to the bindings to Python - GdalOgrInPython where the installation and usage on Linux and Windows platforms is discussed.

您还可能想要检查GDAL Wiki专用于Python - GdalOgrInPython的绑定,其中讨论了Linux和Windows平台上的安装和使用情况。