Matplotlib Qt backend not working

Hi everybody,

I’m trying to run some tests using Qt, which I installed using the action provided here.
Unfortunately I’m encountering an issue when I use the following command from matplotlib:

matplotlib.use('Qt5Agg')

I get the following error which:

2020-08-24T12:07:40.7478857Z tests/sample_test.py:46: 
2020-08-24T12:07:40.7479041Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
2020-08-24T12:07:40.7479517Z /opt/hostedtoolcache/Python/3.6.11/x64/lib/python3.6/site-packages/idt/project.py:21: in <module>
2020-08-24T12:07:40.7479715Z     import idt.series
2020-08-24T12:07:40.7480161Z /opt/hostedtoolcache/Python/3.6.11/x64/lib/python3.6/site-packages/idt/series.py:23: in <module>
2020-08-24T12:07:40.7480631Z     import idt.factory
2020-08-24T12:07:40.7481096Z /opt/hostedtoolcache/Python/3.6.11/x64/lib/python3.6/site-packages/idt/factory.py:19: in <module>
2020-08-24T12:07:40.7481295Z     import idt.data_sources
2020-08-24T12:07:40.7484449Z /opt/hostedtoolcache/Python/3.6.11/x64/lib/python3.6/site-packages/idt/data_sources.py:27: in <module>
2020-08-24T12:07:40.7484673Z     import matplotlib.pyplot as plt
2020-08-24T12:07:40.7485184Z /opt/hostedtoolcache/Python/3.6.11/x64/lib/python3.6/site-packages/matplotlib/pyplot.py:2320: in <module>
2020-08-24T12:07:40.7485391Z     switch_backend(rcParams["backend"])
2020-08-24T12:07:40.7485861Z /opt/hostedtoolcache/Python/3.6.11/x64/lib/python3.6/site-packages/matplotlib/pyplot.py:260: in switch_backend
2020-08-24T12:07:40.7486072Z     class backend_mod(matplotlib.backend_bases._Backend):
2020-08-24T12:07:40.7486546Z /opt/hostedtoolcache/Python/3.6.11/x64/lib/python3.6/site-packages/matplotlib/pyplot.py:261: in backend_mod
2020-08-24T12:07:40.7486766Z     locals().update(vars(importlib.import_module(backend_name)))
2020-08-24T12:07:40.7486976Z /opt/hostedtoolcache/Python/3.6.11/x64/lib/python3.6/importlib/__init__.py:126: in import_module
2020-08-24T12:07:40.7487191Z     return _bootstrap._gcd_import(name[level:], package, level)
2020-08-24T12:07:40.7487687Z /opt/hostedtoolcache/Python/3.6.11/x64/lib/python3.6/site-packages/matplotlib/backends/backend_qt5agg.py:11: in <module>
2020-08-24T12:07:40.7487894Z     from .backend_qt5 import (
2020-08-24T12:07:40.7488370Z /opt/hostedtoolcache/Python/3.6.11/x64/lib/python3.6/site-packages/matplotlib/backends/backend_qt5.py:16: in <module>
2020-08-24T12:07:40.7488590Z     import matplotlib.backends.qt_editor.figureoptions as figureoptions
2020-08-24T12:07:40.7489106Z /opt/hostedtoolcache/Python/3.6.11/x64/lib/python3.6/site-packages/matplotlib/backends/qt_editor/figureoptions.py:11: in <module>
2020-08-24T12:07:40.7489323Z     from matplotlib.backends.qt_compat import QtGui
2020-08-24T12:07:40.7489523Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
2020-08-24T12:07:40.7489631Z 
2020-08-24T12:07:40.7489788Z     """
2020-08-24T12:07:40.7489945Z     
2020-08-24T12:07:40.7490117Z     from distutils.version import LooseVersion
2020-08-24T12:07:40.7490429Z     import os
2020-08-24T12:07:40.7490598Z     import sys
2020-08-24T12:07:40.7490758Z     
2020-08-24T12:07:40.7493659Z     import matplotlib as mpl
2020-08-24T12:07:40.7493833Z     
2020-08-24T12:07:40.7493984Z     
2020-08-24T12:07:40.7494142Z     QT_API_PYQT5 = "PyQt5"
2020-08-24T12:07:40.7494315Z     QT_API_PYSIDE2 = "PySide2"
2020-08-24T12:07:40.7494480Z     QT_API_PYQTv2 = "PyQt4v2"
2020-08-24T12:07:40.7494651Z     QT_API_PYSIDE = "PySide"
2020-08-24T12:07:40.7494838Z     QT_API_PYQT = "PyQt4"   # Use the old sip v1 API (Py3 defaults to v2).
2020-08-24T12:07:40.7495029Z     QT_API_ENV = os.environ.get("QT_API")
2020-08-24T12:07:40.7495379Z     # Mapping of QT_API_ENV to requested binding.  ETS does not support PyQt4v1.
2020-08-24T12:07:40.7495661Z     # (https://github.com/enthought/pyface/blob/c213fa3b24ea988fbc8d288841aecb4a76dd829b/pyface/qt/__init__.py)
2020-08-24T12:07:40.7495875Z     _ETS = {"pyqt5": QT_API_PYQT5, "pyside2": QT_API_PYSIDE2,
2020-08-24T12:07:40.7496076Z             "pyqt": QT_API_PYQTv2, "pyside": QT_API_PYSIDE,
2020-08-24T12:07:40.7496260Z             None: None}
2020-08-24T12:07:40.7496438Z     # First, check if anything is already imported.
2020-08-24T12:07:40.7496601Z     if "PyQt5.QtCore" in sys.modules:
2020-08-24T12:07:40.7496778Z         QT_API = QT_API_PYQT5
2020-08-24T12:07:40.7496952Z     elif "PySide2.QtCore" in sys.modules:
2020-08-24T12:07:40.7497124Z         QT_API = QT_API_PYSIDE2
2020-08-24T12:07:40.7497336Z     elif "PyQt4.QtCore" in sys.modules:
2020-08-24T12:07:40.7497510Z         QT_API = QT_API_PYQTv2
2020-08-24T12:07:40.7497681Z     elif "PySide.QtCore" in sys.modules:
2020-08-24T12:07:40.7497851Z         QT_API = QT_API_PYSIDE
2020-08-24T12:07:40.7498154Z     # Otherwise, check the QT_API environment variable (from Enthought).  This can
2020-08-24T12:07:40.7498366Z     # only override the binding, not the backend (in other words, we check that the
2020-08-24T12:07:40.7498563Z     # requested backend actually matches).
2020-08-24T12:07:40.7498749Z     elif mpl.rcParams["backend"] in ["Qt5Agg", "Qt5Cairo"]:
2020-08-24T12:07:40.7498939Z         if QT_API_ENV in ["pyqt5", "pyside2"]:
2020-08-24T12:07:40.7499119Z             QT_API = _ETS[QT_API_ENV]
2020-08-24T12:07:40.7499288Z         else:
2020-08-24T12:07:40.7499456Z             QT_API = None
2020-08-24T12:07:40.7499635Z     elif mpl.rcParams["backend"] in ["Qt4Agg", "Qt4Cairo"]:
2020-08-24T12:07:40.7502361Z         if QT_API_ENV in ["pyqt4", "pyside"]:
2020-08-24T12:07:40.7502558Z             QT_API = _ETS[QT_API_ENV]
2020-08-24T12:07:40.7502731Z         else:
2020-08-24T12:07:40.7502900Z             QT_API = None
2020-08-24T12:07:40.7503446Z     # A non-Qt backend was selected but we still got there (possible, e.g., when
2020-08-24T12:07:40.7503659Z     # fully manually embedding Matplotlib in a Qt app without using pyplot).
2020-08-24T12:07:40.7503845Z     else:
2020-08-24T12:07:40.7504006Z         try:
2020-08-24T12:07:40.7504179Z             QT_API = _ETS[QT_API_ENV]
2020-08-24T12:07:40.7504354Z         except KeyError as err:
2020-08-24T12:07:40.7504531Z             raise RuntimeError(
2020-08-24T12:07:40.7504726Z                 "The environment variable QT_API has the unrecognized value {!r};"
2020-08-24T12:07:40.7505157Z                 "valid values are 'pyqt5', 'pyside2', 'pyqt', and "
2020-08-24T12:07:40.7505799Z                 "'pyside'") from err
2020-08-24T12:07:40.7505958Z     
2020-08-24T12:07:40.7506113Z     
2020-08-24T12:07:40.7506272Z     def _setup_pyqt5():
2020-08-24T12:07:40.7506458Z         global QtCore, QtGui, QtWidgets, __version__, is_pyqt5, \
2020-08-24T12:07:40.7506646Z             _isdeleted, _getSaveFileName
2020-08-24T12:07:40.7506810Z     
2020-08-24T12:07:40.7506977Z         if QT_API == QT_API_PYQT5:
2020-08-24T12:07:40.7507168Z             from PyQt5 import QtCore, QtGui, QtWidgets
2020-08-24T12:07:40.7507347Z             import sip
2020-08-24T12:07:40.7507526Z             __version__ = QtCore.PYQT_VERSION_STR
2020-08-24T12:07:40.7507709Z             QtCore.Signal = QtCore.pyqtSignal
2020-08-24T12:07:40.7510684Z             QtCore.Slot = QtCore.pyqtSlot
2020-08-24T12:07:40.7510897Z             QtCore.Property = QtCore.pyqtProperty
2020-08-24T12:07:40.7511084Z             _isdeleted = sip.isdeleted
2020-08-24T12:07:40.7511257Z         elif QT_API == QT_API_PYSIDE2:
2020-08-24T12:07:40.7511442Z             from PySide2 import QtCore, QtGui, QtWidgets, __version__
2020-08-24T12:07:40.7511634Z             import shiboken2
2020-08-24T12:07:40.7511829Z             def _isdeleted(obj): return not shiboken2.isValid(obj)
2020-08-24T12:07:40.7512009Z         else:
2020-08-24T12:07:40.7512484Z             raise ValueError("Unexpected value for the 'backend.qt5' rcparam")
2020-08-24T12:07:40.7512701Z         _getSaveFileName = QtWidgets.QFileDialog.getSaveFileName
2020-08-24T12:07:40.7512880Z     
2020-08-24T12:07:40.7513057Z         @mpl.cbook.deprecated("3.3", alternative="QtCore.qVersion()")
2020-08-24T12:07:40.7513244Z         def is_pyqt5():
2020-08-24T12:07:40.7513416Z             return True
2020-08-24T12:07:40.7513585Z     
2020-08-24T12:07:40.7513739Z     
2020-08-24T12:07:40.7513880Z     def _setup_pyqt4():
2020-08-24T12:07:40.7514060Z         global QtCore, QtGui, QtWidgets, __version__, is_pyqt5, \
2020-08-24T12:07:40.7514248Z             _isdeleted, _getSaveFileName
2020-08-24T12:07:40.7514480Z     
2020-08-24T12:07:40.7514645Z         def _setup_pyqt4_internal(api):
2020-08-24T12:07:40.7514828Z             global QtCore, QtGui, QtWidgets, \
2020-08-24T12:07:40.7515016Z                 __version__, is_pyqt5, _isdeleted, _getSaveFileName
2020-08-24T12:07:40.7515205Z             # List of incompatible APIs:
2020-08-24T12:07:40.7515430Z             # http://pyqt.sourceforge.net/Docs/PyQt4/incompatible_apis.html
2020-08-24T12:07:40.7515777Z             _sip_apis = ["QDate", "QDateTime", "QString", "QTextStream", "QTime",
2020-08-24T12:07:40.7515984Z                          "QUrl", "QVariant"]
2020-08-24T12:07:40.7516160Z             try:
2020-08-24T12:07:40.7518898Z                 import sip
2020-08-24T12:07:40.7519087Z             except ImportError:
2020-08-24T12:07:40.7519264Z                 pass
2020-08-24T12:07:40.7519433Z             else:
2020-08-24T12:07:40.7519610Z                 for _sip_api in _sip_apis:
2020-08-24T12:07:40.7519790Z                     try:
2020-08-24T12:07:40.7519977Z                         sip.setapi(_sip_api, api)
2020-08-24T12:07:40.7520166Z                     except ValueError:
2020-08-24T12:07:40.7520346Z                         pass
2020-08-24T12:07:40.7520528Z             from PyQt4 import QtCore, QtGui
2020-08-24T12:07:40.7520715Z             import sip  # Always succeeds *after* importing PyQt4.
2020-08-24T12:07:40.7520906Z             __version__ = QtCore.PYQT_VERSION_STR
2020-08-24T12:07:40.7521100Z             # PyQt 4.6 introduced getSaveFileNameAndFilter:
2020-08-24T12:07:40.7521600Z             # https://riverbankcomputing.com/news/pyqt-46
2020-08-24T12:07:40.7521821Z             if __version__ < LooseVersion("4.6"):
2020-08-24T12:07:40.7522020Z                 raise ImportError("PyQt<4.6 is not supported")
2020-08-24T12:07:40.7522206Z             QtCore.Signal = QtCore.pyqtSignal
2020-08-24T12:07:40.7522387Z             QtCore.Slot = QtCore.pyqtSlot
2020-08-24T12:07:40.7522554Z             QtCore.Property = QtCore.pyqtProperty
2020-08-24T12:07:40.7522735Z             _isdeleted = sip.isdeleted
2020-08-24T12:07:40.7522927Z             _getSaveFileName = QtGui.QFileDialog.getSaveFileNameAndFilter
2020-08-24T12:07:40.7523104Z     
2020-08-24T12:07:40.7523271Z         if QT_API == QT_API_PYQTv2:
2020-08-24T12:07:40.7523452Z             _setup_pyqt4_internal(api=2)
2020-08-24T12:07:40.7523624Z         elif QT_API == QT_API_PYSIDE:
2020-08-24T12:07:40.7523813Z             from PySide import QtCore, QtGui, __version__, __version_info__
2020-08-24T12:07:40.7523999Z             import shiboken
2020-08-24T12:07:40.7524180Z             # PySide 1.0.3 fixed the following:
2020-08-24T12:07:40.7524616Z             # https://srinikom.github.io/pyside-bz-archive/809.html
2020-08-24T12:07:40.7524942Z             if __version_info__ < (1, 0, 3):
2020-08-24T12:07:40.7525136Z                 raise ImportError("PySide<1.0.3 is not supported")
2020-08-24T12:07:40.7527930Z             def _isdeleted(obj): return not shiboken.isValid(obj)
2020-08-24T12:07:40.7528135Z             _getSaveFileName = QtGui.QFileDialog.getSaveFileName
2020-08-24T12:07:40.7528320Z         elif QT_API == QT_API_PYQT:
2020-08-24T12:07:40.7528500Z             _setup_pyqt4_internal(api=1)
2020-08-24T12:07:40.7528669Z         else:
2020-08-24T12:07:40.7529128Z             raise ValueError("Unexpected value for the 'backend.qt4' rcparam")
2020-08-24T12:07:40.7529319Z         QtWidgets = QtGui
2020-08-24T12:07:40.7529490Z     
2020-08-24T12:07:40.7529668Z         @mpl.cbook.deprecated("3.3", alternative="QtCore.qVersion()")
2020-08-24T12:07:40.7529848Z         def is_pyqt5():
2020-08-24T12:07:40.7530018Z             return False
2020-08-24T12:07:40.7530183Z     
2020-08-24T12:07:40.7530336Z     
2020-08-24T12:07:40.7530506Z     if QT_API in [QT_API_PYQT5, QT_API_PYSIDE2]:
2020-08-24T12:07:40.7530678Z         _setup_pyqt5()
2020-08-24T12:07:40.7530856Z     elif QT_API in [QT_API_PYQTv2, QT_API_PYSIDE, QT_API_PYQT]:
2020-08-24T12:07:40.7531034Z         _setup_pyqt4()
2020-08-24T12:07:40.7531182Z     elif QT_API is None:
2020-08-24T12:07:40.7531357Z         if mpl.rcParams["backend"] == "Qt4Agg":
2020-08-24T12:07:40.7531545Z             _candidates = [(_setup_pyqt4, QT_API_PYQTv2),
2020-08-24T12:07:40.7531744Z                            (_setup_pyqt4, QT_API_PYSIDE),
2020-08-24T12:07:40.7531941Z                            (_setup_pyqt4, QT_API_PYQT),
2020-08-24T12:07:40.7532699Z                            (_setup_pyqt5, QT_API_PYQT5),
2020-08-24T12:07:40.7533027Z                            (_setup_pyqt5, QT_API_PYSIDE2)]
2020-08-24T12:07:40.7533206Z         else:
2020-08-24T12:07:40.7533384Z             _candidates = [(_setup_pyqt5, QT_API_PYQT5),
2020-08-24T12:07:40.7533580Z                            (_setup_pyqt5, QT_API_PYSIDE2),
2020-08-24T12:07:40.7533784Z                            (_setup_pyqt4, QT_API_PYQTv2),
2020-08-24T12:07:40.7533985Z                            (_setup_pyqt4, QT_API_PYSIDE),
2020-08-24T12:07:40.7534180Z                            (_setup_pyqt4, QT_API_PYQT)]
2020-08-24T12:07:40.7538591Z         for _setup, QT_API in _candidates:
2020-08-24T12:07:40.7538774Z             try:
2020-08-24T12:07:40.7538948Z                 _setup()
2020-08-24T12:07:40.7539127Z             except ImportError:
2020-08-24T12:07:40.7539302Z                 continue
2020-08-24T12:07:40.7539471Z             break
2020-08-24T12:07:40.7539638Z         else:
2020-08-24T12:07:40.7539811Z >           raise ImportError("Failed to import any qt binding")
2020-08-24T12:07:40.7540003Z E           ImportError: Failed to import any qt binding
2020-08-24T12:07:40.7540103Z 
2020-08-24T12:07:40.7540683Z /opt/hostedtoolcache/Python/3.6.11/x64/lib/python3.6/site-packages/matplotlib/backends/qt_compat.py:173: ImportError
2020-08-24T12:07:40.7540910Z _______________ ElementAdditionTests.test_adding_configurations ________________

What is strange is that locally on my machine it works just fine, but remotely this issues pops out, which led me to the thought that perhaps I’m missing some package, or something’s wrong with the installation of Qt.

Thank you for your help!
Davide

@freydavide ,

Please check with the following methods to see if the problem can be solved:

  1. Try the below command with python shell.

    - name: Install PyQt5
      shell: python
      run: pip install PyQt5
    
  2. Or try the below commands with python shell.

    - name: Re-install matplotlib
      shell: python
      run: |
        pip uninstall matplotlib
        python -m pip install --upgrade pip
        pip install matplotlib
    

Both solutions return invalid syntax error:

2020-09-02T16:47:20.5150977Z ##[group]Run pip install PyQt5
2020-09-02T16:47:20.5151200Z e[36;1mpip install PyQt5e[0m
2020-09-02T16:47:20.5156082Z shell: /opt/hostedtoolcache/Python/3.6.12/x64/bin/python {0}
2020-09-02T16:47:20.5156226Z env:
2020-09-02T16:47:20.5156400Z   pythonLocation: /opt/hostedtoolcache/Python/3.6.12/x64
2020-09-02T16:47:20.5156537Z   Qt5_Dir: /home/runner/work/IDT/Qt/5.12.9/gcc_64
2020-09-02T16:47:20.5156666Z   Qt5_DIR: /home/runner/work/IDT/Qt/5.12.9/gcc_64
2020-09-02T16:47:20.5156806Z   QT_PLUGIN_PATH: /home/runner/work/IDT/Qt/5.12.9/gcc_64/plugins
2020-09-02T16:47:20.5156949Z   QML2_IMPORT_PATH: /home/runner/work/IDT/Qt/5.12.9/gcc_64/qml
2020-09-02T16:47:20.5157097Z ##[endgroup]
2020-09-02T16:47:20.5442693Z   File "/home/runner/work/_temp/ad55ad1f-8360-464d-b026-3cf305136e1e.py", line 1
2020-09-02T16:47:20.5442893Z     pip install PyQt5
2020-09-02T16:47:20.5443036Z               ^
2020-09-02T16:47:20.5443167Z SyntaxError: invalid syntax
2020-09-02T16:47:20.5470713Z ##[error]Process completed with exit code 1.

If I remove python shell, for solution 1 I get the following:

2020-09-02T20:59:32.3953759Z ##[group]Run pytest --cov=idt tests
2020-09-02T20:59:32.3953941Z e[36;1mpytest --cov=idt testse[0m
2020-09-02T20:59:32.4007272Z shell: /bin/bash -e {0}
2020-09-02T20:59:32.4007404Z env:
2020-09-02T20:59:32.4007545Z   pythonLocation: /opt/hostedtoolcache/Python/3.6.12/x64
2020-09-02T20:59:32.4007673Z   Qt5_Dir: /home/runner/work/IDT/Qt/5.12.9/gcc_64
2020-09-02T20:59:32.4007796Z   Qt5_DIR: /home/runner/work/IDT/Qt/5.12.9/gcc_64
2020-09-02T20:59:32.4007926Z   QT_PLUGIN_PATH: /home/runner/work/IDT/Qt/5.12.9/gcc_64/plugins
2020-09-02T20:59:32.4008061Z   QML2_IMPORT_PATH: /home/runner/work/IDT/Qt/5.12.9/gcc_64/qml
2020-09-02T20:59:32.4008185Z ##[endgroup]
2020-09-02T20:59:33.5595606Z ============================= test session starts ==============================
2020-09-02T20:59:33.5596548Z platform linux -- Python 3.6.12, pytest-6.0.1, py-1.9.0, pluggy-0.13.1 -- /opt/hostedtoolcache/Python/3.6.12/x64/bin/python
2020-09-02T20:59:33.5596722Z cachedir: .pytest_cache
2020-09-02T20:59:33.5596974Z rootdir: /home/runner/work/IDT/IDT, configfile: pytest.ini, testpaths: tests
2020-09-02T20:59:33.5597293Z plugins: cov-2.10.1
2020-09-02T20:59:33.8276878Z collecting ... collected 30 items
2020-09-02T20:59:33.8277386Z 
2020-09-02T20:59:33.8358693Z tests/sample_test.py::BaseTests::test_is_existing PASSED                 [  3%]
2020-09-02T20:59:33.8383938Z tests/sample_test.py::BaseTests::test_is_importing PASSED                [  6%]
2020-09-02T20:59:34.3323850Z Fatal Python error: Aborted
2020-09-02T20:59:34.3323989Z 
2020-09-02T20:59:34.3324121Z Current thread 0x00007fe3c639f680 (most recent call first):
2020-09-02T20:59:34.3325089Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pyface/ui/qt4/init.py", line 37 in <module>
2020-09-02T20:59:34.3325395Z   File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
2020-09-02T20:59:34.3325628Z   File "<frozen importlib._bootstrap_external>", line 678 in exec_module
2020-09-02T20:59:34.3325916Z   File "<frozen importlib._bootstrap>", line 665 in _load_unlocked
2020-09-02T20:59:34.3326147Z   File "<frozen importlib._bootstrap>", line 955 in _find_and_load_unlocked
2020-09-02T20:59:34.3326372Z   File "<frozen importlib._bootstrap>", line 971 in _find_and_load
2020-09-02T20:59:34.3326931Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2352 in resolve
2020-09-02T20:59:34.3327462Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2346 in load
2020-09-02T20:59:34.3328172Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pyface/base_toolkit.py", line 223 in import_toolkit
2020-09-02T20:59:34.3328697Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pyface/base_toolkit.py", line 269 in find_toolkit
2020-09-02T20:59:34.3329187Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pyface/toolkit.py", line 23 in <module>
2020-09-02T20:59:34.3329425Z   File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
2020-09-02T20:59:34.3329641Z   File "<frozen importlib._bootstrap_external>", line 678 in exec_module
2020-09-02T20:59:34.3329856Z   File "<frozen importlib._bootstrap>", line 665 in _load_unlocked
2020-09-02T20:59:34.3330075Z   File "<frozen importlib._bootstrap>", line 955 in _find_and_load_unlocked
2020-09-02T20:59:34.3330289Z   File "<frozen importlib._bootstrap>", line 971 in _find_and_load
2020-09-02T20:59:34.3330784Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/traitsui/qt4/toolkit.py", line 24 in <module>
2020-09-02T20:59:34.3331016Z   File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
2020-09-02T20:59:34.3331495Z   File "<frozen importlib._bootstrap_external>", line 678 in exec_module
2020-09-02T20:59:34.3331835Z   File "<frozen importlib._bootstrap>", line 665 in _load_unlocked
2020-09-02T20:59:34.3332185Z   File "<frozen importlib._bootstrap>", line 955 in _find_and_load_unlocked
2020-09-02T20:59:34.3332415Z   File "<frozen importlib._bootstrap>", line 971 in _find_and_load
2020-09-02T20:59:34.3332631Z   File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
2020-09-02T20:59:34.3332846Z   File "<frozen importlib._bootstrap>", line 1023 in _handle_fromlist
2020-09-02T20:59:34.3333392Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/traitsui/qt4/__init__.py", line 25 in <module>
2020-09-02T20:59:34.3333627Z   File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
2020-09-02T20:59:34.3333841Z   File "<frozen importlib._bootstrap_external>", line 678 in exec_module
2020-09-02T20:59:34.3334054Z   File "<frozen importlib._bootstrap>", line 665 in _load_unlocked
2020-09-02T20:59:34.3334277Z   File "<frozen importlib._bootstrap>", line 955 in _find_and_load_unlocked
2020-09-02T20:59:34.3334489Z   File "<frozen importlib._bootstrap>", line 971 in _find_and_load
2020-09-02T20:59:34.3335001Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2352 in resolve
2020-09-02T20:59:34.3335694Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pkg_resources/__init__.py", line 2346 in load
2020-09-02T20:59:34.3336266Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pyface/base_toolkit.py", line 279 in find_toolkit
2020-09-02T20:59:34.3336779Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/traitsui/toolkit.py", line 113 in toolkit
2020-09-02T20:59:34.3337306Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/traitsui/toolkit_traits.py", line 43 in ColorTrait
2020-09-02T20:59:34.3337834Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/traits/trait_factory.py", line 40 in __call__
2020-09-02T20:59:34.3338556Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/traitsui/editors/code_editor.py", line 46 in ToolkitEditorFactory
2020-09-02T20:59:34.3339128Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/traitsui/editors/code_editor.py", line 34 in <module>
2020-09-02T20:59:34.3339362Z   File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
2020-09-02T20:59:34.3339579Z   File "<frozen importlib._bootstrap_external>", line 678 in exec_module
2020-09-02T20:59:34.3339790Z   File "<frozen importlib._bootstrap>", line 665 in _load_unlocked
2020-09-02T20:59:34.3340007Z   File "<frozen importlib._bootstrap>", line 955 in _find_and_load_unlocked
2020-09-02T20:59:34.3340218Z   File "<frozen importlib._bootstrap>", line 971 in _find_and_load
2020-09-02T20:59:34.3340708Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/traitsui/editors/api.py", line 24 in <module>
2020-09-02T20:59:34.3340946Z   File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
2020-09-02T20:59:34.3341167Z   File "<frozen importlib._bootstrap_external>", line 678 in exec_module
2020-09-02T20:59:34.3341597Z   File "<frozen importlib._bootstrap>", line 665 in _load_unlocked
2020-09-02T20:59:34.3341822Z   File "<frozen importlib._bootstrap>", line 955 in _find_and_load_unlocked
2020-09-02T20:59:34.3342033Z   File "<frozen importlib._bootstrap>", line 971 in _find_and_load
2020-09-02T20:59:34.3342575Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/traitsui/editors/__init__.py", line 22 in <module>
2020-09-02T20:59:34.3342811Z   File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
2020-09-02T20:59:34.3343029Z   File "<frozen importlib._bootstrap_external>", line 678 in exec_module
2020-09-02T20:59:34.3343238Z   File "<frozen importlib._bootstrap>", line 665 in _load_unlocked
2020-09-02T20:59:34.3343599Z   File "<frozen importlib._bootstrap>", line 955 in _find_and_load_unlocked
2020-09-02T20:59:34.3343811Z   File "<frozen importlib._bootstrap>", line 971 in _find_and_load
2020-09-02T20:59:34.3344116Z   File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
2020-09-02T20:59:34.3344352Z   File "<frozen importlib._bootstrap>", line 941 in _find_and_load_unlocked
2020-09-02T20:59:34.3344565Z   File "<frozen importlib._bootstrap>", line 971 in _find_and_load
2020-09-02T20:59:34.3345079Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/traitsui/api.py", line 32 in <module>
2020-09-02T20:59:34.3345311Z   File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
2020-09-02T20:59:34.3345529Z   File "<frozen importlib._bootstrap_external>", line 678 in exec_module
2020-09-02T20:59:34.3345745Z   File "<frozen importlib._bootstrap>", line 665 in _load_unlocked
2020-09-02T20:59:34.3345969Z   File "<frozen importlib._bootstrap>", line 955 in _find_and_load_unlocked
2020-09-02T20:59:34.3346177Z   File "<frozen importlib._bootstrap>", line 971 in _find_and_load
2020-09-02T20:59:34.3346819Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/idt/project.py", line 20 in <module>
2020-09-02T20:59:34.3348977Z   File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
2020-09-02T20:59:34.3349535Z   File "<frozen importlib._bootstrap_external>", line 678 in exec_module
2020-09-02T20:59:34.3350406Z   File "<frozen importlib._bootstrap>", line 665 in _load_unlocked
2020-09-02T20:59:34.3350741Z   File "<frozen importlib._bootstrap>", line 955 in _find_and_load_unlocked
2020-09-02T20:59:34.3350972Z   File "<frozen importlib._bootstrap>", line 971 in _find_and_load
2020-09-02T20:59:34.3351356Z   File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
2020-09-02T20:59:34.3351572Z   File "<frozen importlib._bootstrap>", line 1023 in _handle_fromlist
2020-09-02T20:59:34.3351814Z   File "/home/runner/work/IDT/IDT/tests/sample_test.py", line 46 in test_is_opening
2020-09-02T20:59:34.3352723Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/_pytest/python.py", line 180 in pytest_pyfunc_call
2020-09-02T20:59:34.3353576Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pluggy/callers.py", line 187 in _multicall
2020-09-02T20:59:34.3354886Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pluggy/manager.py", line 87 in <lambda>
2020-09-02T20:59:34.3355473Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pluggy/manager.py", line 93 in _hookexec
2020-09-02T20:59:34.3355982Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pluggy/hooks.py", line 286 in __call__
2020-09-02T20:59:34.3356494Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/_pytest/python.py", line 1567 in runtest
2020-09-02T20:59:34.3357041Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/_pytest/runner.py", line 153 in pytest_runtest_call
2020-09-02T20:59:34.3357552Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pluggy/callers.py", line 187 in _multicall
2020-09-02T20:59:34.3358086Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pluggy/manager.py", line 87 in <lambda>
2020-09-02T20:59:34.3358590Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pluggy/manager.py", line 93 in _hookexec
2020-09-02T20:59:34.3359091Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pluggy/hooks.py", line 286 in __call__
2020-09-02T20:59:34.3359592Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/_pytest/runner.py", line 247 in <lambda>
2020-09-02T20:59:34.3360097Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/_pytest/runner.py", line 294 in from_call
2020-09-02T20:59:34.3360996Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/_pytest/runner.py", line 247 in call_runtest_hook
2020-09-02T20:59:34.3361504Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/_pytest/runner.py", line 207 in call_and_report
2020-09-02T20:59:34.3362111Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/_pytest/runner.py", line 117 in runtestprotocol
2020-09-02T20:59:34.3362681Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/_pytest/runner.py", line 100 in pytest_runtest_protocol
2020-09-02T20:59:34.3363176Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pluggy/callers.py", line 187 in _multicall
2020-09-02T20:59:34.3363657Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pluggy/manager.py", line 87 in <lambda>
2020-09-02T20:59:34.3364143Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pluggy/manager.py", line 93 in _hookexec
2020-09-02T20:59:34.3364638Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pluggy/hooks.py", line 286 in __call__
2020-09-02T20:59:34.3365145Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/_pytest/main.py", line 321 in pytest_runtestloop
2020-09-02T20:59:34.3365639Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pluggy/callers.py", line 187 in _multicall
2020-09-02T20:59:34.3366120Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pluggy/manager.py", line 87 in <lambda>
2020-09-02T20:59:34.3366603Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pluggy/manager.py", line 93 in _hookexec
2020-09-02T20:59:34.3367085Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pluggy/hooks.py", line 286 in __call__
2020-09-02T20:59:34.3367743Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/_pytest/main.py", line 296 in _main
2020-09-02T20:59:34.3367902Z   ...
2020-09-02T20:59:45.7762040Z /home/runner/work/_temp/3dcfe556-9b92-4125-9d69-459e902417a5.sh: line 1:  6327 Aborted                 (core dumped) pytest --cov=idt tests
2020-09-02T20:59:45.7762662Z tests/sample_test.py::BaseTests::test_is_opening 
2020-09-02T20:59:45.7770292Z ##[error]Process completed with exit code 134.

and for solution 2:

2020-09-02T17:00:12.1903897Z ##[group]Run pip uninstall matplotlib
2020-09-02T17:00:12.1904196Z e[36;1mpip uninstall matplotlibe[0m
2020-09-02T17:00:12.1904401Z e[36;1mpython -m pip install --upgrade pipe[0m
2020-09-02T17:00:12.1904582Z e[36;1mpip install matplotlibe[0m
2020-09-02T17:00:12.1953509Z shell: /bin/bash -e {0}
2020-09-02T17:00:12.1953728Z env:
2020-09-02T17:00:12.1953930Z   pythonLocation: /opt/hostedtoolcache/Python/3.6.12/x64
2020-09-02T17:00:12.1954104Z   Qt5_Dir: /home/runner/work/IDT/Qt/5.12.9/gcc_64
2020-09-02T17:00:12.1954353Z   Qt5_DIR: /home/runner/work/IDT/Qt/5.12.9/gcc_64
2020-09-02T17:00:12.1954573Z   QT_PLUGIN_PATH: /home/runner/work/IDT/Qt/5.12.9/gcc_64/plugins
2020-09-02T17:00:12.1954822Z   QML2_IMPORT_PATH: /home/runner/work/IDT/Qt/5.12.9/gcc_64/qml
2020-09-02T17:00:12.1955017Z ##[endgroup]
2020-09-02T17:00:12.8258915Z Found existing installation: matplotlib 3.3.1
2020-09-02T17:00:12.9834506Z Uninstalling matplotlib-3.3.1:
2020-09-02T17:00:12.9904366Z   Would remove:
2020-09-02T17:00:12.9928949Z     /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/matplotlib-3.3.1-py3.6-nspkg.pth
2020-09-02T17:00:12.9930016Z     /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/matplotlib-3.3.1.dist-info/*
2020-09-02T17:00:12.9930910Z     /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/matplotlib/*
2020-09-02T17:00:12.9945774Z     /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/mpl_toolkits/axes_grid/*
2020-09-02T17:00:12.9946584Z     /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/mpl_toolkits/axes_grid1/*
2020-09-02T17:00:12.9947264Z     /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/mpl_toolkits/axisartist/*
2020-09-02T17:00:12.9947974Z     /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/mpl_toolkits/mplot3d/*
2020-09-02T17:00:12.9948650Z     /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/mpl_toolkits/tests/*
2020-09-02T17:00:12.9949338Z     /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pylab.py
2020-09-02T17:00:13.4104629Z ERROR: Exception:
2020-09-02T17:00:13.4104946Z Traceback (most recent call last):
2020-09-02T17:00:13.4106886Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pip/_internal/cli/base_command.py", line 216, in _main
2020-09-02T17:00:13.4107151Z     status = self.run(options, args)
2020-09-02T17:00:13.4107749Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pip/_internal/commands/uninstall.py", line 90, in run
2020-09-02T17:00:13.4107941Z     auto_confirm=options.yes, verbose=self.verbosity > 0,
2020-09-02T17:00:13.4108429Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pip/_internal/req/req_install.py", line 685, in uninstall
2020-09-02T17:00:13.4108619Z     uninstalled_pathset.remove(auto_confirm, verbose)
2020-09-02T17:00:13.4109108Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pip/_internal/req/req_uninstall.py", line 388, in remove
2020-09-02T17:00:13.4109578Z     if auto_confirm or self._allowed_to_proceed(verbose):
2020-09-02T17:00:13.4110120Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pip/_internal/req/req_uninstall.py", line 431, in _allowed_to_proceed
2020-09-02T17:00:13.4110501Z     return ask('Proceed (y/n)? ', ('y', 'n')) == 'y'
2020-09-02T17:00:13.4110946Z   File "/opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/pip/_internal/utils/misc.py", line 244, in ask
2020-09-02T17:00:13.4111120Z     response = input(message)
2020-09-02T17:00:13.4111257Z EOFError: EOF when reading a line
2020-09-02T17:00:13.4483840Z Proceed (y/n)? 
2020-09-02T17:00:13.4493533Z ##[error]Process completed with exit code 2.

@freydavide ,

I have created an issue ticket (actions/virtual-environments#1542) to help you report the problems to the appropriate engineering team for further investigation and evaluation.

You can follow this issue ticket and add your comments on it.

1 Like

@freydavide, Hi, Could you please try?

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Setup python
        uses: actions/setup-python@v2
        with:
          python-version: 3.6
          architecture: x64
      - name: Install pyqt5
        run: |
            sudo apt-get install python3-setuptools python3-pyqt5
            python3 -m pip install matplotlib
      - name: Run python script
        run: |
          python3 math.py

@freydavide, Any updates?

Hi!

Sorry for the long wait, still getting a failure unfortunately.

2020-09-10T20:11:28.9024126Z _______________________ MathematicsTests.test_Ndiff2_2nd _______________________
2020-09-10T20:11:28.9024518Z 
2020-09-10T20:11:28.9025032Z self = <tests.unit_tests.MathematicsTests object at 0x7f9d921b3e10>
2020-09-10T20:11:28.9025512Z 
2020-09-10T20:11:28.9025805Z     def test_Ndiff2_2nd(self):
2020-09-10T20:11:28.9026103Z         """
2020-09-10T20:11:28.9026505Z         TEST #000-002
2020-09-10T20:11:28.9026864Z         Testing of the function Ndiff_2_2nd.
2020-09-10T20:11:28.9027195Z         """
2020-09-10T20:11:28.9027431Z     
2020-09-10T20:11:28.9027756Z >       from idt import mathematics
2020-09-10T20:11:28.9028013Z 
2020-09-10T20:11:28.9028304Z tests/unit_tests.py:48: 
2020-09-10T20:11:28.9028632Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
2020-09-10T20:11:28.9029508Z /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/idt/mathematics.py:16: in <module>
2020-09-10T20:11:28.9030271Z     import matplotlib.pyplot as plt
2020-09-10T20:11:28.9031239Z /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/matplotlib/pyplot.py:2320: in <module>
2020-09-10T20:11:28.9031972Z     switch_backend(rcParams["backend"])
2020-09-10T20:11:28.9033028Z /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/matplotlib/pyplot.py:260: in switch_backend
2020-09-10T20:11:28.9033892Z     class backend_mod(matplotlib.backend_bases._Backend):
2020-09-10T20:11:28.9034965Z /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/matplotlib/pyplot.py:261: in backend_mod
2020-09-10T20:11:28.9035814Z     locals().update(vars(importlib.import_module(backend_name)))
2020-09-10T20:11:28.9036566Z /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/importlib/__init__.py:126: in import_module
2020-09-10T20:11:28.9037291Z     return _bootstrap._gcd_import(name[level:], package, level)
2020-09-10T20:11:28.9038386Z /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/matplotlib/backends/backend_qt4agg.py:6: in <module>
2020-09-10T20:11:28.9039140Z     from .backend_qt5agg import (
2020-09-10T20:11:28.9040125Z /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/matplotlib/backends/backend_qt5agg.py:11: in <module>
2020-09-10T20:11:28.9040868Z     from .backend_qt5 import (
2020-09-10T20:11:28.9041823Z /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/matplotlib/backends/backend_qt5.py:16: in <module>
2020-09-10T20:11:28.9043142Z     import matplotlib.backends.qt_editor.figureoptions as figureoptions
2020-09-10T20:11:28.9044558Z /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/matplotlib/backends/qt_editor/figureoptions.py:11: in <module>
2020-09-10T20:11:28.9045538Z     from matplotlib.backends.qt_compat import QtGui
2020-09-10T20:11:28.9046034Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
2020-09-10T20:11:28.9046229Z 
2020-09-10T20:11:28.9046458Z     """
2020-09-10T20:11:28.9046684Z     
2020-09-10T20:11:28.9047122Z     from distutils.version import LooseVersion
2020-09-10T20:11:28.9047581Z     import os
2020-09-10T20:11:28.9047864Z     import sys
2020-09-10T20:11:28.9048120Z     
2020-09-10T20:11:28.9048437Z     import matplotlib as mpl
2020-09-10T20:11:28.9048748Z     
2020-09-10T20:11:28.9048970Z     
2020-09-10T20:11:28.9049250Z     QT_API_PYQT5 = "PyQt5"
2020-09-10T20:11:28.9049609Z     QT_API_PYSIDE2 = "PySide2"
2020-09-10T20:11:28.9049978Z     QT_API_PYQTv2 = "PyQt4v2"
2020-09-10T20:11:28.9050335Z     QT_API_PYSIDE = "PySide"
2020-09-10T20:11:28.9050866Z     QT_API_PYQT = "PyQt4"   # Use the old sip v1 API (Py3 defaults to v2).
2020-09-10T20:11:28.9051375Z     QT_API_ENV = os.environ.get("QT_API")
2020-09-10T20:11:28.9051968Z     # Mapping of QT_API_ENV to requested binding.  ETS does not support PyQt4v1.
2020-09-10T20:11:28.9052716Z     # (https://github.com/enthought/pyface/blob/4b91627c8a8ab2680f62e85af261d1da54675558/pyface/qt/__init__.py)
2020-09-10T20:11:28.9053365Z     _ETS = {"pyqt5": QT_API_PYQT5, "pyside2": QT_API_PYSIDE2,
2020-09-10T20:11:28.9053867Z             "pyqt": QT_API_PYQTv2, "pyside": QT_API_PYSIDE,
2020-09-10T20:11:28.9054255Z             None: None}
2020-09-10T20:11:28.9054669Z     # First, check if anything is already imported.
2020-09-10T20:11:28.9055178Z     if "PyQt5.QtCore" in sys.modules:
2020-09-10T20:11:28.9055582Z         QT_API = QT_API_PYQT5
2020-09-10T20:11:28.9056011Z     elif "PySide2.QtCore" in sys.modules:
2020-09-10T20:11:28.9056447Z         QT_API = QT_API_PYSIDE2
2020-09-10T20:11:28.9056863Z     elif "PyQt4.QtCore" in sys.modules:
2020-09-10T20:11:28.9057277Z         QT_API = QT_API_PYQTv2
2020-09-10T20:11:28.9057707Z     elif "PySide.QtCore" in sys.modules:
2020-09-10T20:11:28.9058130Z         QT_API = QT_API_PYSIDE
2020-09-10T20:11:28.9058675Z     # Otherwise, check the QT_API environment variable (from Enthought).  This can
2020-09-10T20:11:28.9059395Z     # only override the binding, not the backend (in other words, we check that the
2020-09-10T20:11:28.9059989Z     # requested backend actually matches).
2020-09-10T20:11:28.9060520Z     elif mpl.rcParams["backend"] in ["Qt5Agg", "Qt5Cairo"]:
2020-09-10T20:11:28.9061003Z         if QT_API_ENV in ["pyqt5", "pyside2"]:
2020-09-10T20:11:28.9061445Z             QT_API = _ETS[QT_API_ENV]
2020-09-10T20:11:28.9061746Z         else:
2020-09-10T20:11:28.9062024Z             QT_API = None
2020-09-10T20:11:28.9062451Z     elif mpl.rcParams["backend"] in ["Qt4Agg", "Qt4Cairo"]:
2020-09-10T20:11:28.9062923Z         if QT_API_ENV in ["pyqt4", "pyside"]:
2020-09-10T20:11:28.9063292Z             QT_API = _ETS[QT_API_ENV]
2020-09-10T20:11:28.9063592Z         else:
2020-09-10T20:11:28.9063866Z             QT_API = None
2020-09-10T20:11:28.9064603Z     # A non-Qt backend was selected but we still got there (possible, e.g., when
2020-09-10T20:11:28.9065298Z     # fully manually embedding Matplotlib in a Qt app without using pyplot).
2020-09-10T20:11:28.9065781Z     else:
2020-09-10T20:11:28.9066035Z         try:
2020-09-10T20:11:28.9066332Z             QT_API = _ETS[QT_API_ENV]
2020-09-10T20:11:28.9066692Z         except KeyError as err:
2020-09-10T20:11:28.9067073Z             raise RuntimeError(
2020-09-10T20:11:28.9067620Z                 "The environment variable QT_API has the unrecognized value {!r};"
2020-09-10T20:11:28.9068425Z                 "valid values are 'pyqt5', 'pyside2', 'pyqt', and "
2020-09-10T20:11:28.9068998Z                 "'pyside'") from err
2020-09-10T20:11:28.9069276Z     
2020-09-10T20:11:28.9069499Z     
2020-09-10T20:11:28.9069769Z     def _setup_pyqt5():
2020-09-10T20:11:28.9070232Z         global QtCore, QtGui, QtWidgets, __version__, is_pyqt5, \
2020-09-10T20:11:28.9070791Z             _isdeleted, _getSaveFileName
2020-09-10T20:11:28.9071157Z     
2020-09-10T20:11:28.9071445Z         if QT_API == QT_API_PYQT5:
2020-09-10T20:11:28.9071880Z             from PyQt5 import QtCore, QtGui, QtWidgets
2020-09-10T20:11:28.9072287Z             import sip
2020-09-10T20:11:28.9072680Z             __version__ = QtCore.PYQT_VERSION_STR
2020-09-10T20:11:28.9073216Z             QtCore.Signal = QtCore.pyqtSignal
2020-09-10T20:11:28.9073766Z             QtCore.Slot = QtCore.pyqtSlot
2020-09-10T20:11:28.9074357Z             QtCore.Property = QtCore.pyqtProperty
2020-09-10T20:11:28.9074918Z             _isdeleted = sip.isdeleted
2020-09-10T20:11:28.9075330Z         elif QT_API == QT_API_PYSIDE2:
2020-09-10T20:11:28.9075836Z             from PySide2 import QtCore, QtGui, QtWidgets, __version__
2020-09-10T20:11:28.9076330Z             import shiboken2
2020-09-10T20:11:28.9076930Z             def _isdeleted(obj): return not shiboken2.isValid(obj)
2020-09-10T20:11:28.9077396Z         else:
2020-09-10T20:11:28.9078120Z             raise ValueError("Unexpected value for the 'backend.qt5' rcparam")
2020-09-10T20:11:28.9079114Z         _getSaveFileName = QtWidgets.QFileDialog.getSaveFileName
2020-09-10T20:11:28.9079852Z     
2020-09-10T20:11:28.9080374Z         @mpl.cbook.deprecated("3.3", alternative="QtCore.qVersion()")
2020-09-10T20:11:28.9080929Z         def is_pyqt5():
2020-09-10T20:11:28.9081233Z             return True
2020-09-10T20:11:28.9081492Z     
2020-09-10T20:11:28.9081704Z     
2020-09-10T20:11:28.9081974Z     def _setup_pyqt4():
2020-09-10T20:11:28.9082438Z         global QtCore, QtGui, QtWidgets, __version__, is_pyqt5, \
2020-09-10T20:11:28.9083255Z             _isdeleted, _getSaveFileName
2020-09-10T20:11:28.9083630Z     
2020-09-10T20:11:28.9083955Z         def _setup_pyqt4_internal(api):
2020-09-10T20:11:28.9084408Z             global QtCore, QtGui, QtWidgets, \
2020-09-10T20:11:28.9084975Z                 __version__, is_pyqt5, _isdeleted, _getSaveFileName
2020-09-10T20:11:28.9085515Z             # List of incompatible APIs:
2020-09-10T20:11:28.9086228Z             # http://pyqt.sourceforge.net/Docs/PyQt4/incompatible_apis.html
2020-09-10T20:11:28.9087041Z             _sip_apis = ["QDate", "QDateTime", "QString", "QTextStream", "QTime",
2020-09-10T20:11:28.9087546Z                          "QUrl", "QVariant"]
2020-09-10T20:11:28.9088475Z             try:
2020-09-10T20:11:28.9088767Z                 import sip
2020-09-10T20:11:28.9089122Z             except ImportError:
2020-09-10T20:11:28.9089454Z                 pass
2020-09-10T20:11:28.9090135Z             else:
2020-09-10T20:11:28.9090615Z                 for _sip_api in _sip_apis:
2020-09-10T20:11:28.9090927Z                     try:
2020-09-10T20:11:28.9091269Z                         sip.setapi(_sip_api, api)
2020-09-10T20:11:28.9091666Z                     except ValueError:
2020-09-10T20:11:28.9092000Z                         pass
2020-09-10T20:11:28.9092363Z             from PyQt4 import QtCore, QtGui
2020-09-10T20:11:28.9092871Z             import sip  # Always succeeds *after* importing PyQt4.
2020-09-10T20:11:28.9094033Z             __version__ = QtCore.PYQT_VERSION_STR
2020-09-10T20:11:28.9095419Z             # PyQt 4.6 introduced getSaveFileNameAndFilter:
2020-09-10T20:11:28.9096734Z             # https://riverbankcomputing.com/news/pyqt-46
2020-09-10T20:11:28.9097935Z             if __version__ < LooseVersion("4.6"):
2020-09-10T20:11:28.9098442Z                 raise ImportError("PyQt<4.6 is not supported")
2020-09-10T20:11:28.9099463Z             QtCore.Signal = QtCore.pyqtSignal
2020-09-10T20:11:28.9100040Z             QtCore.Slot = QtCore.pyqtSlot
2020-09-10T20:11:28.9100634Z             QtCore.Property = QtCore.pyqtProperty
2020-09-10T20:11:28.9101175Z             _isdeleted = sip.isdeleted
2020-09-10T20:11:28.9102137Z             _getSaveFileName = QtGui.QFileDialog.getSaveFileNameAndFilter
2020-09-10T20:11:28.9102991Z     
2020-09-10T20:11:28.9103297Z         if QT_API == QT_API_PYQTv2:
2020-09-10T20:11:28.9103685Z             _setup_pyqt4_internal(api=2)
2020-09-10T20:11:28.9104078Z         elif QT_API == QT_API_PYSIDE:
2020-09-10T20:11:28.9104571Z             from PySide import QtCore, QtGui, __version__, __version_info__
2020-09-10T20:11:28.9105074Z             import shiboken
2020-09-10T20:11:28.9105468Z             # PySide 1.0.3 fixed the following:
2020-09-10T20:11:28.9106440Z             # https://srinikom.github.io/pyside-bz-archive/809.html
2020-09-10T20:11:28.9107092Z             if __version_info__ < (1, 0, 3):
2020-09-10T20:11:28.9107553Z                 raise ImportError("PySide<1.0.3 is not supported")
2020-09-10T20:11:28.9108163Z             def _isdeleted(obj): return not shiboken.isValid(obj)
2020-09-10T20:11:28.9109028Z             _getSaveFileName = QtGui.QFileDialog.getSaveFileName
2020-09-10T20:11:28.9109750Z         elif QT_API == QT_API_PYQT:
2020-09-10T20:11:28.9110129Z             _setup_pyqt4_internal(api=1)
2020-09-10T20:11:28.9110651Z         else:
2020-09-10T20:11:28.9111363Z             raise ValueError("Unexpected value for the 'backend.qt4' rcparam")
2020-09-10T20:11:28.9111906Z         QtWidgets = QtGui
2020-09-10T20:11:28.9112194Z     
2020-09-10T20:11:28.9112716Z         @mpl.cbook.deprecated("3.3", alternative="QtCore.qVersion()")
2020-09-10T20:11:28.9113271Z         def is_pyqt5():
2020-09-10T20:11:28.9113578Z             return False
2020-09-10T20:11:28.9113845Z     
2020-09-10T20:11:28.9114071Z     
2020-09-10T20:11:28.9114411Z     if QT_API in [QT_API_PYQT5, QT_API_PYSIDE2]:
2020-09-10T20:11:28.9114785Z         _setup_pyqt5()
2020-09-10T20:11:28.9115203Z     elif QT_API in [QT_API_PYQTv2, QT_API_PYSIDE, QT_API_PYQT]:
2020-09-10T20:11:28.9115620Z         _setup_pyqt4()
2020-09-10T20:11:28.9115934Z     elif QT_API is None:
2020-09-10T20:11:28.9116325Z         if mpl.rcParams["backend"] == "Qt4Agg":
2020-09-10T20:11:28.9116808Z             _candidates = [(_setup_pyqt4, QT_API_PYQTv2),
2020-09-10T20:11:28.9117275Z                            (_setup_pyqt4, QT_API_PYSIDE),
2020-09-10T20:11:28.9117673Z                            (_setup_pyqt4, QT_API_PYQT),
2020-09-10T20:11:28.9118072Z                            (_setup_pyqt5, QT_API_PYQT5),
2020-09-10T20:11:28.9118485Z                            (_setup_pyqt5, QT_API_PYSIDE2)]
2020-09-10T20:11:28.9118826Z         else:
2020-09-10T20:11:28.9119201Z             _candidates = [(_setup_pyqt5, QT_API_PYQT5),
2020-09-10T20:11:28.9119660Z                            (_setup_pyqt5, QT_API_PYSIDE2),
2020-09-10T20:11:28.9120074Z                            (_setup_pyqt4, QT_API_PYQTv2),
2020-09-10T20:11:28.9120482Z                            (_setup_pyqt4, QT_API_PYSIDE),
2020-09-10T20:11:28.9120954Z                            (_setup_pyqt4, QT_API_PYQT)]
2020-09-10T20:11:28.9121366Z         for _setup, QT_API in _candidates:
2020-09-10T20:11:28.9121716Z             try:
2020-09-10T20:11:28.9121988Z                 _setup()
2020-09-10T20:11:28.9122333Z             except ImportError:
2020-09-10T20:11:28.9122687Z                 continue
2020-09-10T20:11:28.9123275Z             break
2020-09-10T20:11:28.9123540Z         else:
2020-09-10T20:11:28.9123959Z >           raise ImportError("Failed to import any qt binding")
2020-09-10T20:11:28.9124514Z E           ImportError: Failed to import any qt binding
2020-09-10T20:11:28.9124832Z 
2020-09-10T20:11:28.9125782Z /opt/hostedtoolcache/Python/3.6.12/x64/lib/python3.6/site-packages/matplotlib/backends/qt_compat.py:173: ImportError

@freydavide, Could you please provide minimal steps to reproduce the issue?

Hi,

In this tests I’m just importing a class which has specified the following on just after imports:

import matplotlib
matplotlib.use('Qt4Agg')

If I remove this lines I don’t get any mistake. I assume that if you put it in your file, and run a test with it somehow it could fail.

Best,
Davide

@freydavide,

  1. Using default Python3
jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Install pyqt4 pyqt5
        run: |
            sudo apt-get install python3-setuptools python3-pyqt5 python3-pyqt4
            python3 -m pip install matplotlib
      - name: create testqt5.py
        run: |
          cat <<EOF >testqt5.py
          import matplotlib
          matplotlib.use('Qt5Agg')
          from PyQt5 import QtCore, QtWidgets
          EOF
      - name: Run python script
        run: |
          python3 testqt5.py
      - name: create testqt4.py
        run: |
          cat <<EOF >testqt4.py
          import matplotlib
          matplotlib.use('Qt4Agg')
          from PyQt4 import QtCore, QtGui
          EOF
      - name: Run python script
        run: |
          python3 testqt4.py

pydef

  1. Using Python3 from toolcache you should set PYTHONPATH
jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Setup python
        uses: actions/setup-python@v2
        with:
          python-version: 3.6
          architecture: x64
      - name: Install pyqt4 pyqt5
        run: |
            sudo apt-get install python3-setuptools python3-pyqt5 python3-pyqt4
            python3 -m pip install matplotlib
      - name: create testqt5.py
        run: |
          cat <<EOF >testqt5.py
          import matplotlib
          matplotlib.use('Qt5Agg')
          from PyQt5 import QtCore, QtWidgets
          EOF
      - name: Run python script
        run: |
          python3 testqt5.py 
        env:
          PYTHONPATH: ":/usr/lib/python3/dist-packages"
      - name: create testqt4.py
        run: |
          cat <<EOF >testqt4.py
          import matplotlib
          matplotlib.use('Qt4Agg')
          from PyQt4 import QtCore, QtGui
          EOF
      - name: Run python script
        run: |
          python3 testqt4.py
        env:
          PYTHONPATH: ":/usr/lib/python3/dist-packages"

123

@freydavide, gentle ping.