Connor
Connor

Reputation: 113

Import "flask_sqlalchemy" could not be resolved from source: Pylance

I have tried all of the other solutions before posting here so I hope this does not get removed. Error comes form this line:

from flask_sqlalchemy import SQLAlchemy

I am running the latest version of VSCode. Things I've tried from within my virtual envionment (venv)

1. pip install flask_sqlalchemy
2. pip3 install flask_sqlalchemy
3. pip install flask_sqlalchemy --user

I also have my python VSCode python interpreter set to the the interpreter within the virtual environment.

I can see the flask_sqalchemy is installed within my requirements.txt:

Flask==1.1.1
Flask-SQLAlchemy==2.5.1

I really don't know what else to try at this point.

Upvotes: 1

Views: 2158

Answers (2)

MyronJ
MyronJ

Reputation: 1

I was having the same problem, but I was using pipenv which sets up a special environment for the execution with the python modules installed in that environment. When I execute the "pipenv shell" command, the response shows me the environment that is created and has the version of the interpreter that should be used for this environment.

The line I get is: myuser@Pspec7:~/pydev/flask$ . /home/myuser/.local/share/virtualenvs/flask-E0DF0fBp/bin/activate

When you get to the point where you can select your interpreter: In the interpreter list look for the path that corresponds to your environment.

From the line above, my interpreter was: Python 3.8.10 ('flask-E0DF0fBp')

This was for me. You need to look for your correspoding string. Without setting the interpreter correctly, it cannot look through the packages you have installed.

Upvotes: 0

nicole-reed
nicole-reed

Reputation: 21

I was having the same problem, I messed around a lot reinstalling things so I'm not 100% sure what the perfect solution is but this is what finally worked for me.

View -> Command Pallete -> Python: Select Interpreter -> Select the version that says 'Global'

Then follow the same steps but instead select the version that says 'Recommended'.

I am assuming it somehow reinitialized the version of python I was trying to use.

Upvotes: 2

Related Questions