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
Videos
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 ?
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.
» pip install Flask-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".
Did you create environment?
If no:
1.Create Environment:
On your file system, create a project folder for this tutorial, such as hello_flask.
In that folder, use the following command (as appropriate to your computer) to create a virtual environment named env based on your current interpreter:
# macOS/Linux
sudo apt-get install python3-venv # If needed
python3 -m venv env
# Windows
python -m venv env
2.Select
Open the project folder in VS Code by running code ., or by running VS Code and using the File > Open Folder command.

3. Set
In VS Code, open the Command Palette (View > Command Palette or (Ctrl+Shift+P)). Then select the Python: Select Interpreter command:

4.Activate env
source env/bin/activate (Linux/macOS)
or
env\scripts\activate (Windows)
5.Install Flask
# macOS/Linux
pip3 install flask
# Windows
pip install flask
6. Ensure Pylint is installed within this virtual environment
pip install pylint
Pylint
7. Set your python path like this to your env path like this:
{
"python.pythonPath": "/path/to/your/venv/bin/python",
}
VSCode Workspace
flask via VS Code
I was stuck for 2 days (beginner) with the same problem and tested many ways. I figured out this way:
- Set your python path like this to your env path like this in VSCODE:
{
"python.defaultInterpreterPath": "c:/dev/ala/venv/Scripts/python.exe"
}
- If you are coding in VSCODE (Windows10) I also called from the terminal: python instead of python3 and solved the problem