Python Forum

Full Version: Module 'time' has no attribute 'clock'
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,

I'm posting here, in the hope that you may be able to help me.

I try to run a .py file with Spyder v 4.2.5.

When I try to run the file in spyder, it says :

file ~\anaconda3\lib\site-packages\vpython\rate_control.py:24 in <module>_clock = time.clock
Module 'time' has no attribute 'clock'

And the program doesn't launch.

Any idea of what may cause this issue, please?

What I don't understand, is that I can run this file without problem on another computer.
On the 2 computers, I followed the same steps. I use python v3.8.
The only difference I noticed is that the computer on which the program is working has Spyder v 4.1.5, not 4.2.5.

Thanks a lot !
There used to be a library function time.clock() in python 2. I'm afraid it does not exist any more in python 3. It was deprecated since 3.3 and it seems that it disapeared in 3.8.
Use perf_counter() to get same result as would with removed .clock().
import time

def bar():
   time.sleep(5)

start = time.perf_counter()
bar()
stop = time.perf_counter() - start
print(f'Function bar did use {stop:.3f} sec to run')
Output:
Function bar did use 5.004 sec to run
The problem is in the vpython package. I wonder how this vpython was installed in the site-packages directory for the wrong version of python.
Hi,

Thanks a lot for your answers.

[EDIT : Problem solved ]

So, finally I am able to make it work, pasting the code in Jupyter notebook.
So it must come from the Spyder version that I'm using.