10
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Anirudh\Documents\flask_app\connecting_to_database\application.py", line 2, in <module>
    from flask_sqlalchemy import SQLAlchemy
  File "C:\Users\Anirudh\AppData\Local\Programs\Python\Python38\lib\site-packages\flask_sqlalchemy\__init__.py", line 18, in <module>
    import sqlalchemy
  File "C:\Users\Anirudh\AppData\Local\Programs\Python\Python38\lib\site-packages\sqlalchemy\__init__.py", line 9, in <module>
    from .sql import (
  File "C:\Users\Anirudh\AppData\Local\Programs\Python\Python38\lib\site-packages\sqlalchemy\sql\__init__.py", line 8, in <module>
    from .expression import (
  File "C:\Users\Anirudh\AppData\Local\Programs\Python\Python38\lib\site-packages\sqlalchemy\sql\expression.py", line 34, in <module>
    from .visitors import Visitable
  File "C:\Users\Anirudh\AppData\Local\Programs\Python\Python38\lib\site-packages\sqlalchemy\sql\visitors.py", line 28, in <module>
    from .. import util
  File "C:\Users\Anirudh\AppData\Local\Programs\Python\Python38\lib\site-packages\sqlalchemy\util\__init__.py", line 8, in <module>
    from .compat import callable, cmp, reduce,  \
  File "C:\Users\Anirudh\AppData\Local\Programs\Python\Python38\lib\site-packages\sqlalchemy\util\compat.py", line 234, in <module>
    time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'
jarlh
  • 42,561
  • 8
  • 45
  • 63
  • When submitting a question some background information is advisable. Please indicate OS and version, full Python version, SQLALchemy version, flask_sqlalchemy version. Also where is being run virtualenv, system, etc. Just noticed that visitors.py is in sqlalchemy package. Is that your module? – Adrian Klaver Jun 17 '20 at 19:37

4 Answers4

17

I had this issue with SQLAlchemy 1.2.10. Upgrading to the current version (1.3.18 as of now) fixed the problem

pip install sqlalchemy --upgrade
4

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/

Red
  • 26,798
  • 7
  • 36
  • 58
  • 1
    Except this is coming from the SQLAlchemy compat.py module. I'm not seeing ```time_func = time.clock``` here: https://github.com/sqlalchemy/sqlalchemy/blob/master/lib/sqlalchemy/util/compat.py. I suspect there is a version mismatch in either the Python or SQLAlchemy being used. – Adrian Klaver Jun 17 '20 at 19:30
4

I found a solution that worked for me I have a virtual environment carpet named env in which I installed sqlalchemy So, env\Lib\site-packages\flask_sqlalchemy_init_.py Inside that there is this code:

   if sys.platform == 'win32':
        _timer = time.clock
   else:
        _timer = time.time

And I changed clock to perf_counter() _timer = time.perf_counter()

0

Upgrading to the latest version solves the problem.

pip install flask_sqlalchemy --upgrade

Noah Sheldon
  • 1,461
  • 10
  • 12