如何从Python获取已安装的GDAL/OGR版本?
我想知道怎么从Python中获取安装的GDAL/OGR版本。
我知道有一个叫做gdal-config
的程序,目前我在用这个:
In [3]: import commands
In [4]: commands.getoutput('gdal-config --version')
Out[4]: '1.7.2'
不过,我觉得应该有办法直接用Python的API来做到这一点。有没有人知道怎么做?
2 个回答
16
在osgeo.gdal模块中,__version__
这个属性是一个字符串,里面包含了版本号。
import osgeo.gdal
print osgeo.gdal.__version__
在我的Ubuntu电脑上显示:
>> '1.6.3'
26
gdal.VersionInfo()
是我想要的功能:
>>> osgeo.gdal.VersionInfo()
'1604'
这个在我的Windows电脑和Ubuntu系统上都能正常运行。虽然在我的Windows上使用 gdal.__version__
会出错,但在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__'