Python Forum
Module 'time' has no attribute 'clock'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Module 'time' has no attribute 'clock'
#1
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 !
Reply
#2
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.
Reply
#3
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
Reply
#4
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.
Reply
#5
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Alarm Clock [tkinter] moon 5 682 Aug-07-2024, 05:44 PM
Last Post: deanhystad
  World Clock syntax error OscarBoots 1 626 May-03-2024, 05:20 AM
Last Post: snippsat
  getpass.getpass() results in AttributeError: module 'os' has no attribute 'O_NOCTTY' EarthAndMoon 4 1,529 Oct-03-2023, 02:00 PM
Last Post: deanhystad
  Problem with module time and leap seconds Pedroski55 3 1,667 Oct-07-2022, 11:27 PM
Last Post: Pedroski55
  Clock\time calculation script Drone4four 3 1,895 Jan-21-2022, 03:44 PM
Last Post: ibreeden
  Installing time module Led_Zeppelin 2 14,241 Aug-31-2021, 02:16 PM
Last Post: Led_Zeppelin
  AttributeError: module 'string' has no attribute 'uppercase' Anldra12 10 11,753 Apr-23-2021, 05:30 PM
Last Post: ibreeden
  time.clock not functioning Oldman45 3 3,198 Apr-07-2021, 08:51 AM
Last Post: Oldman45
  module 'os' has no attribute 'tmpfile' whois1230 3 5,038 Jun-12-2020, 03:59 AM
Last Post: ndc85430
  AttributeError: module 'collections' has no attribute 'namedtuple' epgs1975 2 10,935 May-04-2020, 08:10 PM
Last Post: epgs1975

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020