【问题标题】:How can I get the installed GDAL/OGR version from python?如何从 python 获取已安装的 GDAL/OGR 版本?
【发布时间】:2010-07-13 02:00:27
【问题描述】:

如何从 python 获取已安装的 GDAL/OGR 版本?

我知道gdal-config 程序,目前正在使用以下:

In [3]: import commands

In [4]: commands.getoutput('gdal-config --version')
Out[4]: '1.7.2'

但是,我怀疑有一种方法可以使用 python API 本身来做到这一点。有骰子吗?

【问题讨论】:

    标签: python gis geospatial gdal ogr


    【解决方案1】:

    gdal.VersionInfo() 做我想做的事:

    >>> osgeo.gdal.VersionInfo()
    '1604'
    

    这适用于我的 Windows 机器和 Ubuntu 安装。 gdal.__version__ 在我的 Windows 安装中出现错误,尽管它适用于我的 Ubuntu 安装:

    >>> import osgeo.gdal
    >>> print osgeo.gdal.__version__
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    AttributeError: 'module' object has no attribute '__version__'
    

    【讨论】:

      【解决方案2】:

      osgeo.gdal 模块中的__version__ 属性是一个包含版本号的字符串

      import osgeo.gdal
      print osgeo.gdal.__version__
      

      在我的 ubuntu 机器上给出:

      >> '1.6.3'
      

      【讨论】:

      • 在 python3 上,使用:print (osgeo.gdal.__version__)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-19
      • 1970-01-01
      相关资源
      最近更新 更多