Skip to content
Advertisement

AttributeError: module ‘time’ has no attribute ‘clock’ In SQLAlchemy python 3.8.2

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:UsersAnirudhDocumentsflask_appconnecting_to_databaseapplication.py", line 2, in <module>
    from flask_sqlalchemy import SQLAlchemy
  File "C:UsersAnirudhAppDataLocalProgramsPythonPython38libsite-packagesflask_sqlalchemy__init__.py", line 18, in <module>
    import sqlalchemy
  File "C:UsersAnirudhAppDataLocalProgramsPythonPython38libsite-packagessqlalchemy__init__.py", line 9, in <module>
    from .sql import (
  File "C:UsersAnirudhAppDataLocalProgramsPythonPython38libsite-packagessqlalchemysql__init__.py", line 8, in <module>
    from .expression import (
  File "C:UsersAnirudhAppDataLocalProgramsPythonPython38libsite-packagessqlalchemysqlexpression.py", line 34, in <module>
    from .visitors import Visitable
  File "C:UsersAnirudhAppDataLocalProgramsPythonPython38libsite-packagessqlalchemysqlvisitors.py", line 28, in <module>
    from .. import util
  File "C:UsersAnirudhAppDataLocalProgramsPythonPython38libsite-packagessqlalchemyutil__init__.py", line 8, in <module>
    from .compat import callable, cmp, reduce,  
  File "C:UsersAnirudhAppDataLocalProgramsPythonPython38libsite-packagessqlalchemyutilcompat.py", line 234, in <module>
    time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'

Advertisement

Answer

The error occurs because in python 2, there is time.clock(), but in python 3, it has been replaced with time.perf_counter().

Just replace all the time.clock to time.perf_counter, and it should be fine. For more info: https://www.webucator.com/blog/2015/08/python-clocks-explained/

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement