3

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!

Mike
  • 439
  • 1
  • 6
  • 13

2 Answers2

6

UPDATE: As of QGIS 3+, this is now in qgis.core.Qgis.QGIS_VERSION

Original answer:

You can use qgis.utils.QGis.QGIS_VERSION:

>>> import qgis.utils
>>> qgis.utils.QGis.QGIS_VERSION
'2.0.1-Dufour'
Alex Zvoleff
  • 442
  • 2
  • 13
falsetru
  • 357,413
  • 63
  • 732
  • 636
  • Brilliant! I have been digging around for ages trying to find an answer to this. I never thought it would be buried that deep in the package. +1 – Mike Oct 07 '14 at 15:11
1

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
LuWi
  • 133
  • 8