I had the same error. Changed my system python by doing the following in VS Code: Under the view menu select 'show command pallet'. One of the commands you can then select from the command palette is 'Python: Select Interpreter'. Selecting this option will allow you to choose which version of python to use.
Answer from Not_Jimmy_Neutron on Stack OverflowI had the same error. Changed my system python by doing the following in VS Code: Under the view menu select 'show command pallet'. One of the commands you can then select from the command palette is 'Python: Select Interpreter'. Selecting this option will allow you to choose which version of python to use.
This post is pretty old but I found a different solution that might help others out. For me, the issue was my IDE/Python (venv). I am using Visual Studio ver. 1.57.1 as of now on Windows 10.
- Open Visual Code.
- Go to 'View' on the toolbar.
- Click on 'Command Palette...' (or press CTRL + SHIFT + P on Windows).
- Search for: 'Python Select Interpreter'.
- Click on: 'Enter interpreter path...' followed by 'Find...'.
- Go to your (venv) scripts folder:
project_folder/venv/Scripts. - Select
python.exeorpythonw.exeinside of yourproject_folder/venv/Scriptsfolder.
That's all.
The Flask-SQLAlchemy was installed in my virtual environment (venv). But my VSCode was using the system/PC Python interpreter to find the packages instead of the venv.
Hope this helps someone else out.
I am using virtualenv and I install flask-sqlaclchemy using pip install Flask-SQLAlchemy but still the vscode give an error
ImportError: cannot import name 'SQLALchemy' from 'flask_sqlalchemy'
Apparently flask_sqlalchemy is not found, but it is installed : Forums : PythonAnywhere
python - E0401: "Unable to import 'flask_sqlalchemy'" - Stack Overflow
python - Import "flask_sqlalchemy" could not be resolved from source: Pylance - Stack Overflow
Videos
install flask-sqlalchemy out of the virtual environment first.
$ pip install Flask-SQLAlchemy
I had these 2 errors:
Unable to import 'flask_sqlalchemy'
Unable to import 'flask_migrate'
The problem was this line in my models.py file:
id = db.Column(db.Integer, primary_key=True)
I had a comma at end of the line and it caused me an hour of wasted time.
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.
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.
I upgraded my pip and made sure that I installed sql-alchemy. I also am not runnign a virtual environment. How would I fix this issue ?
» pip install Flask-SQLAlchemy
Did you install flask-sqlalchemy? It looks like you have SQLAlchemy installed but not the Flask extension. Try pip install Flask-SQLAlchemy in your project's virtualenv to install it from PyPI.
I just experienced the same problem. Apparently, there is a new distribution method, the extension code is no longer stored under flaskext.
Source: Flask CHANGELOG This worked for me:
from flask_sqlalchemy import SQLAlchemy
- Firstly, create a virtual environment on your terminal.
- Then install Flask by running pip install flask.
- After installing, press CTRL+SHIFT+P.
- Search for Python Interpreter.
- Select your virtual environment.
The problem will be fixed. I have also faced the same issue, but I resolved it by following this procedure.
When I did not install the module "flask", I ran into the problem you described:

The reason is that the module "flask" is not installed in the Python environment we currently use in VSCode.
Please use the shortcut key Ctrl+Shift+` to open a new VSCode terminal, it will automatically enter the currently selected environment, and then use the command "pip show flask" to check the installation location of the module "flask":

If it still shows that the module could not be resolved, it is recommended that you reinstall the module "flask".
I think you have a mismatch between your pip and python versions.
check your pip version pip --version,
if it is pip3
you can try this,
sudo apt-get install python3-sqlalchemy
This should work.
~$ python3
>>import sqlalchemy
If you are on mac, try
pip install flask-sqlalchemy
instead of
pip3 install flask-sqlalchemy.
It works with some warnings, but was able to succesfully connect to the database and create the tables. "FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future. Set it to True or False to suppress this warning."