AttributeError: module ‘time’ has no attribute ‘clock’

Are you getting the error “module ‘time’ has no attribute ‘clock’“? Yes, you have come to the right place. In this tutorial, I will show you how to solve this error.

The error “attributeerror: module ‘time’ has no attribute ‘clock’” occurs because the ‘clock()‘ function has been removed from Python version 3.8.

[Fixed]: AttributeError: module ‘time’ has no attribute ‘clock’

You can use these functions instead of ‘clock()‘: “time.perf_counter()” or “time.process_time()“.

You can use this function “perf_counter()” like this:

import time

start_time = time.perf_counter()
time.sleep(1)
end_time = time.perf_counter()

print(end_time - start_time)

You can also use “process_time()” like this:

import time

start_time = time.process_time()
time.sleep(1)
end_time = time.process_time()

print(end_time - start_time)

The “perf_counter” function returns the number of fractional seconds of a performance counter. and the “process_time” function returns the number of fractional seconds of the system and the user CPU time of the current process.

[Fixed]: module ‘time’ has no attribute ‘clock’ (Not using ‘.clock()’)

You can get this error even if you are not using the ‘time.clock()‘ function. The reason is you are using some modules that are using the clock() function in the background. You can update that module or replace it if the model is not maintained anymore.

[Fixed] AttributeError: ‘list’ object has no attribute ‘astype’

The most common reasons for these errors are using the unmaintained “PyCrypto” module or having an older version of “sqlalchemy” installed in your system.

# If you are using PyCrypto
pip3 uninstall PyCrypto
pip3 install pycryptodome

# If you use SQLAlchemy
pip install SQLAlchemy --upgrade 

Conclusion on AttributeError: module ‘time’ has no attribute ‘clock’

Programmers, we discussed how we can solve this error “attributeerror: module ‘time’ has no attribute ‘clock’“. If you are still getting the error please let us know in the comments section.

The error “attributeerror: module ‘time’ has no attribute ‘clock’” occurs because the ‘clock()‘ function has been removed from Python version 3.8. You can use these functions instead of ‘clock()‘: “time.perf_counter()” or “time.process_time()“.

Leave a Reply