VS Code not able to recognize SQLAlchemy
Asked Answered
O

2

6

I have installed SQLAlchemy through the command line by:

pip install SQLAlchemy

and have also done:

pip install Flask-SQLAlchemy 

I am trying to run these lines and it tells me I have an unresolved import:

from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker

I have ran

>>>import sqlalchemy
>>>sqlalchemy.__version__

In the python interpreter and it says I have version 1.3.17 installed so I believe that means that sqlalchemy is installed correctly but VS Code does not see it for some reason.

Any help is appreciated.

Olsewski answered 21/5, 2020 at 22:30 Comment(0)
D
8

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. enter image description here

3. Set

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

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

Discursion answered 21/5, 2020 at 22:48 Comment(3)
I created an environment and followed your steps and VS Code still says my SQLAlchemy imports are unresolvedOlsewski
Follow the 6th stepDiscursion
Please follow step 6 and 7 and be sure if you installed pip install pylint.Discursion
I
0

I was stuck for 2 days (beginner) with the same problem and tested many ways. I figured out this way:

  1. Set your python path like this to your env path like this in VSCODE:
{   
  "python.defaultInterpreterPath": "c:/dev/ala/venv/Scripts/python.exe" 
}
  1. If you are coding in VSCODE (Windows10) I also called from the terminal: python instead of python3 and solved the problem
Invade answered 12/12, 2021 at 21:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.