0

I can not even get off the ground with this one. Flask is not my first framework, but it is new to me since so many updates have went by. ok, so my problem is that I am running into this error when I am running my python file within the cli to import the db variable to work with it using sqlite.

>>> from __init__ import db
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\*myusername*\Desktop\*appname*\__init__.py", line 2, in <module>
    from sqlalchemy import SQLAlchemy
ImportError: cannot import name 'SQLAlchemy' from 'sqlalchemy' (C:\Users\*myusername*\Envs\*appname*\lib\site-packages\sqlalchemy\__init__.py)

My code is listed below, it isn't much but this is all I like from finishing my project. If anyone has any pointers here let me know. I am guessing it's something simple (it usually is) that I am just overlooking.

from flask import Flask, render_template
from sqlalchemy import SQLAlchemy

app = Flask('*appname*')

# Database functionality

app.config['SQLALCHEMY_DATABASE_URI']= 'sqlite:///C:/Users/*myusername*/Desktop/*appname*/'

db = SQLAlchemy(app)

class usersTable(db.Model):
    userid = db.Column(db.Integer, primary_key=True)
    fname = db.Column(db.Text)
    lname = db.Column(db.Text)
    email = db.Column(db.LargeBinary)
    username = db.Column(db.LargeBinary)
    password = db.Column(db.LargeBinary)
    joined = db.Column(db.Date)

Thanks in advance guys. Normally my backend language is PHP, so I am branching out and this is really starting to get on my nerves lol.

1
  • are you using flask_sqlalchemy? Commented Mar 21, 2020 at 2:53

1 Answer 1

2

First you need to install Flask-SQLAlchemy library using: pip install flask-sqlalchemy

Then import it like this in your code, from flask_sqlalchemy import SQLAlchemy

If you want to learn more, check this minimal application using flask-sqlalchemy.

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

11 Comments

I get this error when I run it now, I am not trying to sound needy but I can't wrap my head around this for some reason:
ModuleNotFoundError: No module named 'flask_sqlalchemy'
I did install flask_sqlalchemy
sorry wrong library. flask-sqlalchemy is the correct one
The underscore fixed it. Thanks for your help!
|

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.