timeByFrames.py demo not working with the new v3.1.0 release (no module named PyQt4)

Hi Guys,
I just installed the new v3.1 release (fantastic job for the new keyboard class). The timeByFrames demo of the coder is broken and returns the error reported below. I think it is important to fix it because the demo is very useful to check the precision of frame flips. The bug seems to concern pylab.

Note that I installed PsychoPy using the standalone program, and I am running windows 10.

Problem compiling: [Errno 13] Permission denied: 'C:\\Program Files (x86)\\PsychoPy3\\lib\\site-packages\\psychopy\\demos\\coder\\timing\\__pycache__\\timeByFrames.cpython-36.pyc.2834910788104'
##### Running: C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\demos\coder\timing\timeByFrames.py #####
pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\demos\coder\timing\timeByFrames.py", line 23, in <module>
    import pylab
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\pylab.py", line 1, in <module>
    from matplotlib.pylab import *
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\matplotlib\pylab.py", line 252, in <module>
    from matplotlib import cbook, mlab, pyplot as plt
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\matplotlib\pyplot.py", line 115, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\matplotlib\backends\__init__.py", line 62, in pylab_setup
    [backend_name], 0)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\matplotlib\backends\backend_qt4agg.py", line 9, in <module>
    from .backend_qt5agg import (
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\matplotlib\backends\backend_qt5agg.py", line 15, in <module>
    from .backend_qt5 import (
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\matplotlib\backends\backend_qt5.py", line 19, in <module>
    import matplotlib.backends.qt_editor.figureoptions as figureoptions
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\matplotlib\backends\qt_editor\figureoptions.py", line 20, in <module>
    import matplotlib.backends.qt_editor.formlayout as formlayout
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\matplotlib\backends\qt_editor\formlayout.py", line 54, in <module>
    from matplotlib.backends.qt_compat import QtGui, QtWidgets, QtCore
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\matplotlib\backends\qt_compat.py", line 153, in <module>
    from PyQt4 import QtCore, QtGui
ModuleNotFoundError: No module named 'PyQt4'

(putting aside I’m not sure if they fixed this in 3.1.2, or I had done something here to fix)
If you put matplotlib.use('Qt5Agg') in line 22, you should be good to go.

I’m having the same issue on v3.1.2 on Win10.

Apologies. I keep forgetting to update the demo code but, yes, @mirh has the right solution. Change the code to use ‘Qt5Agg’ (and save somewhere that you have write permissions) and you should be good to go.


Just an FYI.
The demo timeByFrames.py was not working for me on PsychoPy 2020.2.6, Mac OS 10.14.
Removing the normed argument to pylab.hist() in line 72 fixed it:
pylab.hist(intervalsMS, 50, histtype=‘stepfilled’) #, normed=0