Esempio n. 1
0
def check_pandoc_version():
    """Returns True if minimal pandoc version is met.

    Raises
    ------
    PandocMissing
      If pandoc is unavailable.
    """
    v = get_pandoc_version()
    if v is None:
        warnings.warn(
            "Sorry, we cannot determine the version of pandoc.\n"
            "Please consider reporting this issue and include the"
            "output of pandoc --version.\nContinuing...",
            RuntimeWarning,
            stacklevel=2)
        return False
    ok = check_version(v, _minimal_version)
    if not ok:
        warnings.warn(
            "You are using an old version of pandoc (%s)\n" % v +
            "Recommended version is %s.\nTry updating." % _minimal_version +
            "http://johnmacfarlane.net/pandoc/installing.html.\nContinuing with doubts...",
            RuntimeWarning,
            stacklevel=2)
    return ok
Esempio n. 2
0
def import_pyqt4(version=2):
    """
    Import PyQt4

    Parameters
    ----------
    version : 1, 2, or None
      Which QString/QVariant API to use. Set to None to use the system
      default

    ImportErrors rasied within this function are non-recoverable
    """
    # The new-style string API (version=2) automatically
    # converts QStrings to Unicode Python strings. Also, automatically unpacks
    # QVariants to their underlying objects.
    import sip

    if version is not None:
        sip.setapi('QString', version)
        sip.setapi('QVariant', version)

    from PyQt4 import QtGui, QtCore, QtSvg

    if not check_version(QtCore.PYQT_VERSION_STR, '4.7'):
        raise ImportError("IPython requires PyQt4 >= 4.7, found %s" %
                          QtCore.PYQT_VERSION_STR)

    # Alias PyQt-specific functions for PySide compatibility.
    QtCore.Signal = QtCore.pyqtSignal
    QtCore.Slot = QtCore.pyqtSlot

    # query for the API version (in case version == None)
    version = sip.getapi('QString')
    api = QT_API_PYQTv1 if version == 1 else QT_API_PYQT
    return QtCore, QtGui, QtSvg, api
Esempio n. 3
0
def get_options():
    """Return a list of acceptable QT APIs, in decreasing order of
    preference
    """
    #already imported Qt somewhere. Use that
    loaded = loaded_api()
    if loaded is not None:
        return [loaded]

    mpl = sys.modules.get('matplotlib', None)

    if mpl is not None and not check_version(mpl.__version__, '1.0.2'):
        #1.0.1 only supports PyQt4 v1
        return [QT_API_PYQT_DEFAULT]

    qt_api = os.environ.get('QT_API', None)
    if qt_api is None:
        #no ETS variable. Ask mpl, then use default fallback path
        return matplotlib_options(mpl) or [
            QT_API_PYQT_DEFAULT, QT_API_PYSIDE, QT_API_PYQT5
        ]
    elif qt_api not in _qt_apis:
        raise RuntimeError("Invalid Qt API %r, valid values are: %r" %
                           (qt_api, ', '.join(_qt_apis)))
    else:
        return [qt_api]
def import_pyqt4(version=2):
    """
    Import PyQt4

    Parameters
    ----------
    version : 1, 2, or None
      Which QString/QVariant API to use. Set to None to use the system
      default

    ImportErrors rasied within this function are non-recoverable
    """
    # The new-style string API (version=2) automatically
    # converts QStrings to Unicode Python strings. Also, automatically unpacks
    # QVariants to their underlying objects.
    import sip

    if version is not None:
        sip.setapi('QString', version)
        sip.setapi('QVariant', version)

    from PyQt4 import QtGui, QtCore, QtSvg

    if not check_version(QtCore.PYQT_VERSION_STR, '4.7'):
        raise ImportError("IPython requires PyQt4 >= 4.7, found %s" %
                          QtCore.PYQT_VERSION_STR)

    # Alias PyQt-specific functions for PySide compatibility.
    QtCore.Signal = QtCore.pyqtSignal
    QtCore.Slot = QtCore.pyqtSlot

    # query for the API version (in case version == None)
    version = sip.getapi('QString')
    api = QT_API_PYQTv1 if version == 1 else QT_API_PYQT
    return QtCore, QtGui, QtSvg, api
Esempio n. 5
0
def load_ipython_extension(ip):
    """Load the extension in IPython."""
    
    print("""The Cython magic has been move to the Cython package, hence """)
    print("""`%load_ext cythonmagic` is deprecated; Please use `%load_ext Cython` instead.""")
    
    if Cython is None or not version.check_version(Cython.__version__, "0.21"):
        print("You need Cython version >=0.21 to use the Cython magic")
        return 
    print("""\nThough, because I am nice, I'll still try to load it for you this time.""")
    Cython.load_ipython_extension(ip)
Esempio n. 6
0
def load_ipython_extension(ip):
    """Load the extension in IPython."""
    
    print("""The Cython magic has been moved to the Cython package, hence """)
    print("""`%load_ext cythonmagic` is deprecated; please use `%load_ext Cython` instead.""")
    
    if Cython is None or not version.check_version(Cython.__version__, "0.21"):
        print("You need Cython version >=0.21 to use the Cython magic")
        return 
    print("""\nThough, because I am nice, I'll still try to load it for you this time.""")
    Cython.load_ipython_extension(ip)
Esempio n. 7
0
def check_for_zmq(minimum_version, required_by='Someone'):
    try:
        import zmq
    except ImportError:
        raise ImportError("%s requires pyzmq >= %s"%(required_by, minimum_version))
    
    pyzmq_version = zmq.__version__
    
    if not check_version(pyzmq_version, minimum_version):
        raise ImportError("%s requires pyzmq >= %s, but you have %s"%(
                        required_by, minimum_version, pyzmq_version))
Esempio n. 8
0
def check_for_zmq(minimum_version, module='IPython.kernel.zmq'):
    try:
        import zmq
    except ImportError:
        raise ImportError("%s requires pyzmq >= %s"%(module, minimum_version))

    pyzmq_version = zmq.__version__
    
    if not check_version(pyzmq_version, minimum_version):
        raise ImportError("%s requires pyzmq >= %s, but you have %s"%(
                        module, minimum_version, pyzmq_version))
Esempio n. 9
0
def check_for_zmq(minimum_version, module='IPython.kernel.zmq'):
    try:
        import zmq
    except ImportError:
        raise ImportError("%s requires pyzmq >= %s" %
                          (module, minimum_version))

    pyzmq_version = zmq.__version__

    if not check_version(pyzmq_version, minimum_version):
        raise ImportError("%s requires pyzmq >= %s, but you have %s" %
                          (module, minimum_version, pyzmq_version))
Esempio n. 10
0
def check_for_zmq(minimum_version, required_by='Someone'):
    try:
        import zmq
    except ImportError:
        raise ImportError("%s requires pyzmq >= %s" %
                          (required_by, minimum_version))

    pyzmq_version = zmq.__version__

    if not check_version(pyzmq_version, minimum_version):
        raise ImportError("%s requires pyzmq >= %s, but you have %s" %
                          (required_by, minimum_version, pyzmq_version))
Esempio n. 11
0
def has_binding(api):
    """Safely check for PyQt4/5 or PySide, without importing
       submodules

       Parameters
       ----------
       api : str [ 'pyqtv1' | 'pyqt' | 'pyqt5' | 'pyside' | 'pyqtdefault']
            Which module to check for

       Returns
       -------
       True if the relevant module appears to be importable
    """
    # we can't import an incomplete pyside and pyqt4
    # this will cause a crash in sip (#1431)
    # check for complete presence before importing
    module_name = {
        QT_API_PYSIDE: 'PySide',
        QT_API_PYQT: 'PyQt4',
        QT_API_PYQTv1: 'PyQt4',
        QT_API_PYQT5: 'PyQt5',
        QT_API_PYQT_DEFAULT: 'PyQt4'
    }
    module_name = module_name[api]

    import imp

    def find_module(module):
        return "%s.%s" % (module_name, module) in sys.modules.keys()

    try:
        # importing top level PyQt4/PySide module is ok...
        # FIXME: Once imported a top module this method will always deliver true.
        #        mod = __import__(module_name)
        # ...importing submodules is not
        # imp.find_module('QtCore', mod.__path__)
        if (find_module("QtGui") or find_module("QtSvg")
                or find_module("QtCore")):
            return True
        # imp.find_module('QtGui', mod.__path__)
        # imp.find_module('QtSvg', mod.__path__)
        if api == QT_API_PYQT5 and find_module("QtWidgets"):
            # QT5 requires QtWidgets too
            # imp.find_module('QtWidgets', mod.__path__)
            return True

        #we can also safely check PySide version
        if api == QT_API_PYSIDE:
            return check_version(mod.__version__, '1.0.3')
        else:
            return True
    except ImportError:
        return False
Esempio n. 12
0
def check_pandoc_version():
    """Returns True if minimal pandoc version is met.

    Exceptions
    ----------
    PandocMissing will be raised if pandoc is unavailable.
    """
    v = get_pandoc_version()
    ok = check_version(v , _minimal_version )
    if not ok:
        warnings.warn( "You are using an old version of pandoc (%s)\n" % v + 
                       "Recommended version is %s.\nTry updating." % _minimal_version + 
                       "http://johnmacfarlane.net/pandoc/installing.html.\nContinuing with doubts...",
                       RuntimeWarning, stacklevel=2)
    return ok
Esempio n. 13
0
def _verify_node(cmd):
    """Verify that the node command exists and is at least the minimum supported
    version of node.

    Parameters
    ----------
    cmd : string
        Node command to verify (i.e 'node')."""
    try:
        out, err, return_code = get_output_error_code([cmd, '--version'])
    except OSError:
        # Command not found
        return False
    if return_code:
        # Command error
        return False
    return check_version(out.lstrip('v'), '0.9.12')
Esempio n. 14
0
def get_options():
    """Return a list of acceptable QT APIs, in decreasing order of
    preference
    """
    #already imported Qt somewhere. Use that
    loaded = loaded_api()
    if loaded is not None:
        return [loaded]

    mpl = sys.modules.get('matplotlib', None)

    if mpl is not None and not check_version(mpl.__version__, '1.0.2'):
        #1.0.1 only supports PyQt4 v1
        return [QT_API_PYQT_DEFAULT]

    qt_api = os.environ.get('QT_API', None)
    if qt_api is None:
Esempio n. 15
0
def _verify_node(cmd):
    """Verify that the node command exists and is at least the minimum supported
    version of node.

    Parameters
    ----------
    cmd : string
        Node command to verify (i.e 'node')."""
    try:
        out, err, return_code = get_output_error_code([cmd, '--version'])
    except OSError:
        # Command not found
        return False
    if return_code:
        # Command error
        return False
    return check_version(out.lstrip('v'), '0.9.12')
Esempio n. 16
0
def check_pandoc_version():
    """Returns True if minimal pandoc version is met.

    Raises
    ------
    PandocMissing
      If pandoc is unavailable.
    """
    v = get_pandoc_version()
    ok = check_version(v, _minimal_version)
    if not ok:
        warnings.warn(
            "You are using an old version of pandoc (%s)\n" % v +
            "Recommended version is %s.\nTry updating." % _minimal_version +
            "http://johnmacfarlane.net/pandoc/installing.html.\nContinuing with doubts...",
            RuntimeWarning,
            stacklevel=2)
    return ok
Esempio n. 17
0
def has_binding(api):
    """Safely check for PyQt4/5 or PySide, without importing
       submodules

       Parameters
       ----------
       api : str [ 'pyqtv1' | 'pyqt' | 'pyqt5' | 'pyside' | 'pyqtdefault']
            Which module to check for

       Returns
       -------
       True if the relevant module appears to be importable
    """
    # we can't import an incomplete pyside and pyqt4
    # this will cause a crash in sip (#1431)
    # check for complete presence before importing
    module_name = {
        QT_API_PYSIDE: 'PySide',
        QT_API_PYQT: 'PyQt4',
        QT_API_PYQTv1: 'PyQt4',
        QT_API_PYQT5: 'PyQt5',
        QT_API_PYQT_DEFAULT: 'PyQt4'
    }
    module_name = module_name[api]

    import imp
    try:
        #importing top level PyQt4/PySide module is ok...
        mod = import_module(module_name)
        #...importing submodules is not
        imp.find_module('QtCore', mod.__path__)
        imp.find_module('QtGui', mod.__path__)
        imp.find_module('QtSvg', mod.__path__)
        if api == QT_API_PYQT5:
            # QT5 requires QtWidgets too
            imp.find_module('QtWidgets', mod.__path__)

        #we can also safely check PySide version
        if api == QT_API_PYSIDE:
            return check_version(mod.__version__, '1.0.3')
        else:
            return True
    except ImportError:
        return False
Esempio n. 18
0
def _verify_node(cmd):
    """Verify that the node command exists and is at least the minimum supported
    version of node.

    Parameters
    ----------
    cmd : string
        Node command to verify (i.e 'node')."""
    try:
        p = subprocess.Popen([cmd, "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        out, _ = p.communicate()
        out = out.decode("utf8", "replace")
    except OSError:
        # Command not found
        return False
    if p.returncode:
        # Command error
        return False
    return check_version(out.lstrip("v"), "0.9.12")
Esempio n. 19
0
def has_binding(api):
    """Safely check for PyQt4/5 or PySide, without importing
       submodules

       Parameters
       ----------
       api : str [ 'pyqtv1' | 'pyqt' | 'pyqt5' | 'pyside' | 'pyqtdefault']
            Which module to check for

       Returns
       -------
       True if the relevant module appears to be importable
    """
    # we can't import an incomplete pyside and pyqt4
    # this will cause a crash in sip (#1431)
    # check for complete presence before importing
    module_name = {QT_API_PYSIDE: 'PySide',
                   QT_API_PYQT: 'PyQt4',
                   QT_API_PYQTv1: 'PyQt4',
                   QT_API_PYQT5: 'PyQt5',
                   QT_API_PYQT_DEFAULT: 'PyQt4'}
    module_name = module_name[api]

    import imp
    try:
        #importing top level PyQt4/PySide module is ok...
        mod = import_module(module_name)
        #...importing submodules is not
        imp.find_module('QtCore', mod.__path__)
        imp.find_module('QtGui', mod.__path__)
        imp.find_module('QtSvg', mod.__path__)
        if api == QT_API_PYQT5:
            # QT5 requires QtWidgets too
            imp.find_module('QtWidgets', mod.__path__)

        #we can also safely check PySide version
        if api == QT_API_PYSIDE:
            return check_version(mod.__version__, '1.0.3')
        else:
            return True
    except ImportError:
        return False
Esempio n. 20
0
def _verify_node(cmd):
    """Verify that the node command exists and is at least the minimum supported
    version of node.

    Parameters
    ----------
    cmd : string
        Node command to verify (i.e 'node')."""
    try:
        p = subprocess.Popen([cmd, '--version'],
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE)
        out, _ = p.communicate()
        out = out.decode('utf8', 'replace')
    except OSError:
        # Command not found
        return False
    if p.returncode:
        # Command error
        return False
    return check_version(out.lstrip('v'), '0.9.12')
Esempio n. 21
0
def get_options():
    """Return a list of acceptable QT APIs, in decreasing order of
    preference
    """
    #already imported Qt somewhere. Use that
    loaded = loaded_api()
    if loaded is not None:
        return [loaded]

    mpl = sys.modules.get('matplotlib', None)

    if mpl is not None and not check_version(mpl.__version__, '1.0.2'):
        #1.0.1 only supports PyQt4 v1
        return [QT_API_PYQT_DEFAULT]

    if os.environ.get('QT_API', None) is None:
        #no ETS variable. Ask mpl, then use either
        return matplotlib_options(mpl) or [QT_API_PYQT_DEFAULT, QT_API_PYSIDE]

    #ETS variable present. Will fallback to external.qt
    return None
Esempio n. 22
0
def get_options():
    """Return a list of acceptable QT APIs, in decreasing order of
    preference
    """
    #already imported Qt somewhere. Use that
    loaded = loaded_api()
    if loaded is not None:
        return [loaded]

    mpl = sys.modules.get('matplotlib', None)

    if mpl is not None and not check_version(mpl.__version__, '1.0.2'):
        #1.0.1 only supports PyQt4 v1
        return [QT_API_PYQT_DEFAULT]

    if os.environ.get('QT_API', None) is None:
        #no ETS variable. Ask mpl, then use either
        return matplotlib_options(mpl) or [QT_API_PYQT_DEFAULT, QT_API_PYSIDE]

    #ETS variable present. Will fallback to external.qt
    return None
Esempio n. 23
0
def has_binding_new(api):
    """Safely check for PyQt4/5, PySide or PySide2, without importing submodules

    Supports Python >= 3.4

        Parameters
        ----------
        api : str [ 'pyqtv1' | 'pyqt' | 'pyqt5' | 'pyside' | 'pyside2' | 'pyqtdefault']
             Which module to check for

        Returns
        -------
        True if the relevant module appears to be importable
     """
    module_name = api_to_module[api]
    from importlib.util import find_spec

    required = ['QtCore', 'QtGui', 'QtSvg']
    if api in (QT_API_PYQT5, QT_API_PYSIDE2):
        # QT5 requires QtWidgets too
        required.append('QtWidgets')

    for submod in required:
        try:
            spec = find_spec('%s.%s' % (module_name, submod))
        except ImportError:
            # Package (e.g. PyQt5) not found
            return False
        else:
            if spec is None:
                # Submodule (e.g. PyQt5.QtCore) not found
                return False

    if api == QT_API_PYSIDE:
        # We can also safely check PySide version
        import PySide
        return check_version(PySide.__version__, '1.0.3')

    return True
Esempio n. 24
0
def has_binding_new(api):
    """Safely check for PyQt4/5, PySide or PySide2, without importing submodules

    Supports Python >= 3.4

        Parameters
        ----------
        api : str [ 'pyqtv1' | 'pyqt' | 'pyqt5' | 'pyside' | 'pyside2' | 'pyqtdefault']
             Which module to check for

        Returns
        -------
        True if the relevant module appears to be importable
     """
    module_name = api_to_module[api]
    from importlib.util import find_spec

    required = ['QtCore', 'QtGui', 'QtSvg']
    if api in (QT_API_PYQT5, QT_API_PYSIDE2):
        # QT5 requires QtWidgets too
        required.append('QtWidgets')

    for submod in required:
        try:
            spec = find_spec('%s.%s' % (module_name, submod))
        except ImportError:
            # Package (e.g. PyQt5) not found
            return False
        else:
            if spec is None:
                # Submodule (e.g. PyQt5.QtCore) not found
                return False

    if api == QT_API_PYSIDE:
        # We can also safely check PySide version
        import PySide
        return check_version(PySide.__version__, '1.0.3')

    return True
Esempio n. 25
0
def check_pandoc_version():
    """Returns True if minimal pandoc version is met.

    Raises
    ------
    PandocMissing
      If pandoc is unavailable.
    """
    v = get_pandoc_version()
    if v is None:
        warnings.warn("Sorry, we cannot determine the version of pandoc.\n"
                      "Please consider reporting this issue and include the"
                      "output of pandoc --version.\nContinuing...",
                      RuntimeWarning, stacklevel=2)
        return False
    ok = check_version(v, _minimal_version)
    if not ok:
        warnings.warn("You are using an old version of pandoc (%s)\n" % v +
                      "Recommended version is %s.\nTry updating." % _minimal_version +
                      "http://johnmacfarlane.net/pandoc/installing.html.\nContinuing with doubts...",
                      RuntimeWarning, stacklevel=2)
    return ok
Esempio n. 26
0
def get_options():
    """Return a list of acceptable QT APIs, in decreasing order of
    preference
    """
    #already imported Qt somewhere. Use that
    loaded = loaded_api()
    if loaded is not None:
        return [loaded]

    mpl = sys.modules.get('matplotlib', None)

    if mpl is not None and not check_version(mpl.__version__, '1.0.2'):
        #1.0.1 only supports PyQt4 v1
        return [QT_API_PYQT_DEFAULT]

    qt_api = os.environ.get('QT_API', None)
    if qt_api is None:
        #no ETS variable. Ask mpl, then use either
        return matplotlib_options(mpl) or [QT_API_PYQT_DEFAULT, QT_API_PYSIDE]
    elif qt_api not in _qt_apis:
        raise RuntimeError("Invalid Qt API %r, valid values are: %r" %
                           (qt_api, ', '.join(_qt_apis)))
    else:
        return [qt_api]
Esempio n. 27
0
def prepare_pyqt4():
    # For PySide compatibility, use the new-style string API that automatically
    # converts QStrings to Unicode Python strings. Also, automatically unpack
    # QVariants to their underlying objects.
    import sip
    sip.setapi('QString', 2)
    sip.setapi('QVariant', 2)


# Select Qt binding, using the QT_API environment variable if available.
QT_API = os.environ.get('QT_API')
if QT_API is None:
    pyside_found = False
    try:
        import PySide
        if not check_version(PySide.__version__, '1.0.3'):
            # old PySide, fallback on PyQt
            raise ImportError
        # we can't import an incomplete pyside and pyqt4
        # this will cause a crash in sip (#1431)
        # check for complete presence before importing
        import imp
        imp.find_module("QtCore", PySide.__path__)
        imp.find_module("QtGui", PySide.__path__)
        imp.find_module("QtSvg", PySide.__path__)
        pyside_found = True
        from PySide import QtCore, QtGui, QtSvg
        QT_API = QT_API_PYSIDE
    except ImportError:
        try:
            prepare_pyqt4()
Esempio n. 28
0
def prepare_pyqt4():
    # For PySide compatibility, use the new-style string API that automatically
    # converts QStrings to Unicode Python strings. Also, automatically unpack
    # QVariants to their underlying objects.
    import sip
    sip.setapi('QString', 2)
    sip.setapi('QVariant', 2)

# Select Qt binding, using the QT_API environment variable if available.
QT_API = os.environ.get('QT_API')
if QT_API is None:
    pyside_found = False
    try:
        import PySide
        if not check_version(PySide.__version__, '1.0.3'):
            # old PySide, fallback on PyQt
            raise ImportError
        # we can't import an incomplete pyside and pyqt4
        # this will cause a crash in sip (#1431)
        # check for complete presence before importing
        import imp
        imp.find_module("QtCore", PySide.__path__)
        imp.find_module("QtGui", PySide.__path__)
        imp.find_module("QtSvg", PySide.__path__)
        pyside_found = True
        from PySide import QtCore, QtGui, QtSvg
        QT_API = QT_API_PYSIDE
    except ImportError:
        try:
            prepare_pyqt4()
Esempio n. 29
0
from IPython.utils.version import check_version
try:
    import argparse
    # don't use system argparse if older than 1.1:
    if not check_version(argparse.__version__, '1.1'):
        raise ImportError
    else:
        from argparse import *
        from argparse import SUPPRESS
except (ImportError, AttributeError):
    from ._argparse import *
    from ._argparse import SUPPRESS
Esempio n. 30
0
import os

import terminado
from IPython.utils.version import check_version

if not check_version(terminado.__version__, '0.3.3'):
    raise ImportError("terminado >= 0.3.3 required, found %s" % terminado.__version__)

from terminado import NamedTermManager
from tornado.log import app_log
from IPython.html.utils import url_path_join as ujoin
from .handlers import TerminalHandler, TermSocket
from . import api_handlers

def initialize(webapp):
    shell = os.environ.get('SHELL', 'sh')
    terminal_manager = webapp.settings['terminal_manager'] = NamedTermManager(shell_command=[shell])
    terminal_manager.log = app_log
    base_url = webapp.settings['base_url']
    handlers = [
        (ujoin(base_url, r"/terminals/(\w+)"), TerminalHandler),
        (ujoin(base_url, r"/terminals/websocket/(\w+)"), TermSocket,
             {'term_manager': terminal_manager}),
        (ujoin(base_url, r"/api/terminals"), api_handlers.TerminalRootHandler),
        (ujoin(base_url, r"/api/terminals/(\w+)"), api_handlers.TerminalHandler),
    ]
    webapp.add_handlers(".*$", handlers)
Esempio n. 31
0
        except:
            fallback on PySide
else:
    use PyQt @v2 or PySide, depending on QT_API
    because ETS doesn't work with PyQt @v1.

"""

import os
import sys

from IPython.utils.warn import warn
from IPython.utils.version import check_version

matplotlib = sys.modules.get('matplotlib')
if matplotlib and not check_version(matplotlib.__version__, '1.0.2'):
    # 1.0.1 doesn't support pyside or v2, so stick with PyQt @v1,
    # and ignore everything else
    from PyQt4 import QtCore, QtGui
else:
    # ask QT_API ETS variable *first*
    QT_API = os.environ.get('QT_API', None)
    if QT_API is None:
        # QT_API not set, ask matplotlib if it was imported (e.g. `pylab=qt`)
        if matplotlib:
            mpqt = matplotlib.rcParams.get('backend.qt4', None)
        else:
            mpqt = None
        if mpqt is None:
            # matplotlib not imported or had nothing to say.
            try: