. Advertisement .
. Advertisement .
Python is a programming language that is very familiar to those who learn to program, and it supports most of today’s operating systems. This is also a language famous for its rigor, speed, and power, and is available in all operating systems. However, along with the advantages, in the process of using you can also encounter many errors. If you are facing this problem “AttributeError: module ‘time’ has no attribute ‘clock’” when run SQLAlchemy python 3.8.2, continue to follow our article to find the solution.
When does the error ”AttributeError: module ‘time’ has no attribute ‘clock’” happen?
The error ”AttributeError: module ‘time’ has no attribute ‘clock’” happens when you are running 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'
This error happens due to the
clock() function has been deleted since Python v3.8.
How to solve “AttributeError: module ‘time’ has no attribute ‘clock’”
The Python language has two versions. The difference between Python 2 and 3 is that Python 2 will be minimally supported in the future and Python 3 will continue to grow further in the future. Both share similar capabilities but some of their syntax is different. Either way, both are used to build applications.
Option 1: Change time.clock() to time.perf_counter()
In this case, because the line time.clock() in python 2 version has been replaced to time.perf_counter() in python 3 so error has occurred. The solution is very simple that you just need to change them for each other, it means change all line time.clock to time.perf_counter, the problem is considered to be solved.
Option 2: Utilize PyCryptodome instead of PyCrypto
PyCrypto is no longer supported, so if you are using it, you should utilize PyCryptodome instead of PyCrypto. First, let’s use this command to uninstall PyCrypto.
pip3 uninstall PyCrypto
Then you need to set up PyCryptodome. You can use the below command to install it.
pip3 install -U PyCryptodome
Option 3: Replace time.clock with time.time
Another solution to solve “AttributeError: module ‘time’ has no attribute ‘clock’” is replacing time.clock with time.time. Let’s follow these steps to do that:
- Step 1: Finding C:\Users\ssc\anaconda3\envs\pythonProject2\Lib\site-packages\sqlalchemy\util this folder.
- Step 2: Choosing compat.py file and opening it.
- Step 3: Looking for
- Step 4: Replacing
- Step 5: Saving it.
Option 4: Use pip install your_module –upgrade command to update error
In the case, the error “AttributeError: module ‘time’ has no attribute ‘clock’” happens because of another external module, you have to use
pip install your_module --upgrade command to update it.
You must either find a substitute or use a Python version lower than 3.8 if the module isn’t upgraded to stop using the
If you follow the above solutions, your error can be solved.
Python is an object-oriented language with a wide range of applications. So, understanding the structure and architecture of Python will be a very good reference foundation when you want to move on to learning other programming languages. Hopefully through our guide, you will soon solve your problem about “AttributeError: module ‘time’ has no attribute ‘clock’”. If you have any questions, please contact us for answers. Thanks for reading!