PyQtGraph is a library for creating plots in PyQt applications.
Recent changes in Python 3.8 can cause an AttributeError if you're using older versions of PyQtGraph.
I got an error when running your plotting script above at line
from pyqtgraph import PlotWidget, plot, which gave the errorException has occurred: AttributeError module 'time' has no attribute 'clock'
Why does the time.clock AttributeError occur?
The clock member was removed from the time module in Python 3.8. Older versions of PyQtGraph still reference time.clock, which triggers the AttributeError: module 'time' has no attribute 'clock' message when running on Python 3.8 or later.
This error typically appears when you first import PyQtGraph, for example with from pyqtgraph import PlotWidget, because the library internally calls time.clock() during initialization.
How to fix module 'time' has no attribute 'clock'
In your own code, replace time.clock() with either time.perf_counter() or time.process_time(), depending on your requirements. For libraries such as PyQtGraph you'll need to update to a version that includes the fix.
Upgrade PyQtGraph
This was fixed in PyQtGraph v0.11.0rc0 and is available via PyPI. Upgrade PyQtGraph with:
pip install --upgrade pyqtgraph
After upgrading, restart your Python environment and re-run your script. The AttributeError should no longer appear.
Install the development version from GitHub
If you need to access the latest development version of PyQtGraph before an official release, you can install the current master branch from GitHub directly:
pip install git+https://github.com/pyqtgraph/pyqtgraph.git
Downgrade Python (not recommended)
Alternatively, you can downgrade to Python 3.7, where time.clock is still available (though deprecated). This is not recommended as a long-term solution, since Python 3.7 has reached end of life.
Summary
The AttributeError: module 'time' has no attribute 'clock' error occurs because time.clock() was removed in Python 3.8. The simplest fix is to upgrade PyQtGraph to version 0.11.0 or later using pip install --upgrade pyqtgraph. If you encounter time.clock in your own code, replace it with time.perf_counter() or time.process_time().
PyQt/PySide 1:1 Coaching with Martin Fitzpatrick
Save yourself time and frustration. Get one on one help with your Python GUI projects. Working together with you I'll identify issues and suggest fixes, from bugs and usability to architecture and maintainability.