I have searched around and seen some similar questions, but nothing that helps with my issue. I am learning Flask and following a video on Flask Authentication.
I am working from a venv specific to this project, running python 3.10 and have installed Flask-Login:
(.venv) >> pip3 freeze
bcrypt==4.0.1
click==8.1.3
dnspython==2.2.1
email-validator==1.3.0
Flask==2.2.2
Flask-Bcrypt==1.0.1
Flask-Login==0.6.2
Flask-SQLAlchemy==3.0.2
Flask-WTF==1.0.1
greenlet==2.0.1
idna==3.4
itsdangerous==2.1.2
Jinja2==3.1.2
MarkupSafe==2.1.1
SQLAlchemy==1.4.45
Werkzeug==2.2.2
WTForms==3.0.1
I'm just at the start of this project so my code is very simple:
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
from flask_login import UserMixin
app = Flask(__name__)
db = SQLAlchemy()
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
app.config['SECRET_KEY'] = 'XXXXXXXXXXXXXXXXXXXXXX'
db.init_app(app)
@app.route('/')
def home():
return render_template('home.html')
@app.route('/login')
def login():
return render_template('login.html')
@app.route('/register')
def register():
return render_template('register.html')
if __name__ == '__main__':
app.run(debug=True)
The problem is that VSCode doesn't see flask_login as being able to import despite being installed in the proper venv where my other imports are also located. The below is from the Problems tab:
Import "flask_login" could not be resolved
Nothing I have found online seems to help with my situation. I have seen some that suggest the editor is just having problems and to restart - which I did but did not help. I uninstalled and reinstalled and also had no success.
I am not sure what I am missing...
CodePudding user response:
Choose the correct interpreter.
Ctrl Shift P --> Python:Select Interpreter
Select an interpreter with the
flask_login
package installedChoose the interpreter you want to use
Create a new terminal activation environment
Install the
flask_login
package for the currently selected interpreter
Or you can use the following code to print out the current interpreter path, and then copy the path to install the flask_login
package for the current interpreter
import sys
print(sys.executable)