python-qgis version information

若如初见. 提交于 2019-12-12 13:47:30

问题


Can someone tell me how I get the version information for python-qgis?

I have tried all the usual foo.version or foo.__version__ or foo.VERSION. If someone knows how to do this, it would be a great help!


回答1:


You can use qgis.utils.QGis.QGIS_VERSION:

>>> import qgis.utils
>>> qgis.utils.QGis.QGIS_VERSION
'2.0.1-Dufour'



回答2:


In QGIS3, this has changed to (Qgis instead of QGis)

>>> import qgis.utils
>>> qgis.utils.Qgis.QGIS_VERSION
'3.1.0-Master'

A way to figure out whether the version is >=3.0 or not seems to be

(QGIS >=3.0)

>>> import qgis.utils
>>> hasattr(qgis.utils, 'Qgis')
True

(QGIS <= 2.18)

>>> import qgis.utils
>>> hasattr(qgis.utils, 'Qgis')
False


来源:https://stackoverflow.com/questions/26239144/python-qgis-version-information

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!