AttributeError module 'time' has no attribute 'clock'

Fix PyQtGraph 'time.clock' error in Python 3.8+
Heads up! You've already completed this tutorial.

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 error Exception 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:

bash
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:

bash
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().

Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak

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.

Book Now 60 mins ($195)

Martin Fitzpatrick

AttributeError module 'time' has no attribute 'clock' was written by Martin Fitzpatrick.

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt. Martin founded PythonGUIs to provide easy to follow GUI programming tutorials to the Python community. He has written a number of popular Python books on the subject.