0

I'm a beginner in Python. I'm using Pycharm and Flask to create a web app. I have written the following code but its giving me an error. Kindly assist I want to create a database.

from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///test.db'
db = SQLAlchemy(app)


class Todo(db.Model):
    id = db.Column(db.Interger, primary_key=True)
    content = db.Column(db.String(200), nullable=False)
    completed = db.Colmnn(db.Interger, default=0)
    date_created = db.Column(db.DateTime, default=datetime.utcnow)

    def __repr__(self):
        return '<Task %r>' % self.id


@app.route('/')
def index():
    return render_template('index.html')


if __name__ == '__main__':
    app.run(debug=True)
'''

Error:

"C:\Users\Takunda Mafuta\AppData\Local\Programs\Python\Python38-32\python.exe" "C:/Users/Takunda Mafuta/Videos/lgT Personal Development/Data Science/Python/Tutorials/FreeCodeCamp/Exercise/TaskMaster.py"
Traceback (most recent call last):
  File "C:/Users/Takunda Mafuta/Videos/lgT Personal Development/Data Science/Python/Tutorials/FreeCodeCamp/Exercise/TaskMaster.py", line 2, in <module>
    from flask_sqlalchemy import SQLAlchemy
  File "C:\Users\Takunda Mafuta\AppData\Local\Programs\Python\Python38-32\lib\site-packages\flask_sqlalchemy\__init__.py", line 13, in <module>
    import sqlalchemy
  File "C:\Users\Takunda Mafuta\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\__init__.py", line 8, in <module>
    from . import util as _util  # noqa
  File "C:\Users\Takunda Mafuta\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\util\__init__.py", line 14, in <module>
    from ._collections import coerce_generator_arg  # noqa
  File "C:\Users\Takunda Mafuta\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\util\_collections.py", line 16, in <module>
    from .compat import binary_types
  File "C:\Users\Takunda Mafuta\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\util\compat.py", line 264, in <module>
    time_func = time.clock
AttributeError: module 'time' has no attribute 'clock'

Process finished with exit code 1
4
  • Did you create a local module named time.py? Commented Jan 31, 2020 at 10:03
  • No I didn't, let me do so. Commented Jan 31, 2020 at 10:05
  • I have created one, what's the way forward now? Commented Jan 31, 2020 at 10:07
  • You should remove it and then either downgrade to Python 3.7 or use one of the alternatives suggested in one of the answers. Commented Jan 31, 2020 at 11:57

1 Answer 1

2

If you are using python 3.8, then time.clock() is :

Deprecated since version 3.3, will be removed in version 3.8: The behaviour of this function depends on the platform: use perf_counter() or process_time() instead, depending on your requirements, to have a well defined behaviour.

Please read the document here.

Also Update sqlalchemy to v1.3.6 for Windows + Py3.8 fixes.. Read it here : https://github.com/sqlalchemy/sqlalchemy/issues/4731

Sign up to request clarification or add additional context in comments.

4 Comments

I didn't get it neither in the document. Where exactly was I using time.clock() that I need to change to perf_counter() or process_time(). Pardon me for my ignorance, I am a newbie in programming.
what is your sqlalchemy version...?? If you are on the latest version of python, make sure to get the latest version of sqlalchemy.
SQLAlchemy 1.2.17 and flask_sqlalchemy 2.4.1
Update sqlalchemy to v1.3.6 for Windows + Py3.8 fixes.. This is that this document says. Read it here : github.com/sqlalchemy/sqlalchemy/issues/4731

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.