mako AttributeError: module 'time' has no attribute 'clock' python3.9
- User
mako AttributeError: module 'time' has no attribute 'clock' python3.9
- Assistant
In Python 3.8 and later versions, the
time.clock()function was removed because it was deprecated since Python 3.3. The recommended replacements fortime.clock()depend on what you were using it for:-
Measure wall time (actual elapsed time): Use
time.perf_counter(), which provides a high-resolution timer to measure short durations.start_time = time.perf_counter() # Code block whose execution time you want to measure end_time = time.perf_counter() elapsed_time = end_time - start_time print(f"Elapsed time: {elapsed_time} seconds") -
Measure CPU time: Use
time.process_time(), which returns the CPU time used by the program.start_cpu_time = time.process_time() # Code block whose CPU time usage you want to measure end_cpu_time = time.process_time() elapsed_cpu_time = end_cpu_time - start_cpu_time print(f"CPU time: {elapsed_cpu_time} seconds")
If you are working with the
makolibrary and it internally usestime.clock(), you should make sure that you are using the latest version of the library, as this issue may have been fixed in newer releases. You can update the library using pip:pip install --upgrade makoIf updating the library is not feasible, you'll need to manually patch the code by replacing any instances of
time.clock()with one of the alternatives mentioned above, based on the context of its usage. -