Search code examples
pythonexceptionqgistraceback

exceptions/traceback not showing after importing qgis-utils


Following on from a question I asked about getting the version information from python-qgis, with a brilliant solution provided by @falsetru, I am running into a problem whereby importing qgis.utils seems to hide all exceptions. Running the following code in the interpreter, I get no traceback, or anything useful following a raised exception, see below.

>>> import qgis.utils
>>> qgis.utils.QGis.QGIS_VERSION
'2.4.0-Chugiak'
>>> raise Exception('boof!')
>>>

Could someone tell me how I can turn back on traceback after importing qgis-utils or another way of getting the version information from python-qgis without needing to import utils?

Many thanks!


Solution

  • I have found a solution, which allows me to avoid using the utils module to get the version information, and uses the core module instead.

    >>> import qgis.core
    >>> qgis.core.Qgis.QGIS_VERSION
    '2.4.0-Chugiak'
    >>> raise Exception('boof!')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    Exception: boof!
    

    This doesn't provide a full answer to my question, but does provide a work-around to get the version information for python-qgis.