1. Open the Command Palette (Ctrl+Shift+P), then select the Python: Select Interpreter. From the list, select the virtual environment in your project folder that starts with .env.

  2. Run Terminal: Create New Integrated Terminal (Ctrl+Shift+` or from the Command Palette), which creates a terminal and automatically activates the virtual environment by running its activation script.

  3. Install sqlalchemy and mongoengine with command pip install. Once installing them successfully, there will intellisense when you import them and no warnings shown.

Besides, the folder .vscode is to store Workspace settings as well as debugging and task configurations.

Answer from Molly Wang-MSFT on Stack Overflow
Discussions

python - VS Code / Pylance / Pylint Cannot resolve import - Stack Overflow
The Summary I have a python import that works when run from the VS Code terminal, but that VS Code's editor is giving warnings about. Also, "Go to Definition" doesn't work. The Problem I ... More on stackoverflow.com
🌐 stackoverflow.com
Import "[module]" could not be resolvedPylance (reportMissingImports)
I am learning a Python book, so I created folder for each chapter to storage code. Working directory is as follows: book └─chapter1 ├─a.py ─b.py b.py import a When I "open by code" in "book" folde... More on github.com
🌐 github.com
45
August 13, 2020
Why Python imports cannot be resolved by Pylance in VS Code, if the package is located in a shared folder? - Stack Overflow
I am using Pylance extension in VS Code. Some packages import cannot be resolved by Pylance. I found out that these packages are located in a shared folder and the UNC Path of this folder is in the More on stackoverflow.com
🌐 stackoverflow.com
Pylance: import from same directory could not be resolved
Interestingly enough, if I use ... can then resolve it. However, the code will not run then because of the error: ImportError: attempted relative import with no known parent package. So basically, I have to choose between Pylance linting and the code actually running right now. System Information: Linux Virtual Machine Ubuntu 20.04 Python 3.8.5 VScode v1.53.2 Python ... More on github.com
🌐 github.com
4
February 13, 2021
🌐
GitHub
gist.github.com › krisbolton › 20159d66f1d919c9c2380c96b6ac3915
VSCode import could not be resolved by Pylance (reportMissingImports) · GitHub
You need to tell Pylance where pip has installed the module you are trying to import. This is called an "additional path". Find the location of the module. In the VSCode terminal within your project enter the python interpreter by typing python.
🌐
Sentry
sentry.io › sentry answers › vs code › fix pylance resolvemissingimports in vs code
Fix Pylance resolveMissingImports in VS Code | Sentry
July 15, 2024 - Select the Python interpreter in your virtual environment – it should be the top option, with a “Recommended” tag. If you previously installed fastapi to the virtual environment, the resolveMissingImports error should now disappear.
🌐
Safjan
safjan.com › home › note › vscode problem - import could not be resolved...
VSCode problem - import could not be resolved from the source (Pylance)
September 10, 2024 - Learn how to resolve the "Import 'pandas' could not be resolved from the source" warning in VSCode's Jupyter notebook using Pylance by ensuring the correct Python interpreter and virtual environment are activated.
Top answer
1 of 7
13

I had the same problem but with all kinds of packages. My solution was to go to the VSCode settings and search for "python.analysis.extraPaths", and add the path to your site-packages.

In my case, I added C:\Code\Python39\Lib\site-packages, and now it's working fine.

2 of 7
9

tldr;

TensorFlow defines some of its modules in a way that pylint & pylance aren't able to recognize. These errors don't necessarily indicate an incorrect setup.

To Fix:

  • pylint: The pylint warnings are safely ignored.
  • Intellisense: The best way I know of at the moment to fix Intellisense is to replace the imports with the modules they are aliasing (found by importing alias in a repl as x then running help(x)). Because the target of the alias in my case is an internal name, you probably don't want to check in these changes to source control. Not ideal.

Details

Regarding the linting: It seems that tensorflow defines its modules in a way that the tools can't understand. Also, it appears that the package is an alias of some kind to another package. For example:

Copyimport tensorflow.compat.v1 as tf
tf.estimator.RunConfig()

The above code gives the pylint warning and breaks intellisense. But if you manually import the above in a REPL and run help(tf), it shows you the below package, which you can use instead:

Copyimport tensorflow_core._api.v1.compat.v1 as tf
tf.estimator.RunConfig()

This second example does not cause the pylint warning. Also the Intellisense features (Go to definition, Ctrl+Click, etc) work with this second example.

However, based on the _api, it looks like that second package name is an internal namespace, so I'm guessing it is probably best to only use this internal name for local debugging.

Confirmation/Tickets

  • pylint: I've found a ticket about pylint having issues with a couple tensorflow imports that looks related.
  • Intellisense: I've opened a ticket with pylance.
🌐
DEV Community
dev.to › climentea › how-to-solve-pylance-missing-imports-in-vscode-359b
How to solve Pylance 'missing imports' in vscode - DEV Community
February 3, 2021 - A folder named .vscode will be created once you select a different interpreter than the default one. Inside .vscode you will have a settings.json file. In settings.json file you have to add the paths from which you import what's needed in extraPaths: { "python.pythonPath": "/home/youruser/.virtualenvs/app-FzQGSFjf/bin/python", "python.analysis.extraPaths": ["app", "another/path/etc"] } In my case, app folder was not known by Pylance.
Find elsewhere
🌐
Esri Community
community.esri.com › t5 › python-questions › pylance-in-vs-code › td-p › 1342663
Solved: Pylance in VS Code - Esri Community
October 27, 2023 - Solved: Been having issues with the latest Pylance for VS Code not properly following arcpy imports and specifically hanging up the Pylance server on the arcpy
🌐
GitHub
github.com › microsoft › pylance-release › issues › 236
Import "[module]" could not be resolvedPylance (reportMissingImports) · Issue #236 · microsoft/pylance-release
August 13, 2020 - Import "a" could not be resolved · However, module "a" is really imported and it works well. If I delete "python.languageServer": "Pylance" and use Jedi, yellow wavy line won't show up. In addition, if i "open by code" in "chapter1" folder, yellow wavy line won't show up.
Author   jiangzhuochi
🌐
GitHub
github.com › microsoft › pylance-release › issues › 948
Pylance: import from same directory could not be resolved · Issue #948 · microsoft/pylance-release
February 13, 2021 - Interestingly enough, if I use from .Mesh import *, Pylance can then resolve it. However, the code will not run then because of the error: ImportError: attempted relative import with no known parent package. So basically, I have to choose between Pylance linting and the code actually running right now. System Information: Linux Virtual Machine Ubuntu 20.04 Python 3.8.5 VScode v1.53.2 Python Extension for VScode v2021.1.502429796 Pylance v2021.2.2
Author   adamwass
🌐
Bobby Hadz
bobbyhadz.com › blog › python-import-could-not-be-resolved-from-source-pylance-reportmissingmodulesource
Import "X" could not be resolved from source Pylance [Fixed] | bobbyhadz
April 10, 2024 - The error "Import "X" could not be resolved from source Pylance" occurs when the imported module is not installed or you have selected the incorrect Python interpreter in your IDE (e.g.
🌐
Readthedocs
micropython-stubs.readthedocs.io › en › main › 22_vscode.html
Configuring VSCode, Pylance or Pyright — Micropython-Stubs 1.23.0 documentation
Note: If you’ve previously set a language server and want to try Pylance, make sure you’ve set "python.languageServer": "Default" or "Pylance" in your settings.json file using the text editor, or using the Settings Editor UI. ... If you have created a .venv make sure to also select it in VSCode using F1, >Python: select interpreter or the UX ... After installing the stubs you may see some warnings that the source code for some of the commonly used modules are not found: Import "machine" could not be resolved from source Import "time" could not be resolved from source Import "urequests" could not be resolved from source
🌐
NVIDIA Developer Forums
forums.developer.nvidia.com › omniverse › archive › general discussion
Pylance can not resolve my external dependencies installed via pipapi - General Discussion - NVIDIA Developer Forums
November 17, 2022 - I added the yaml package in my extension.toml [python.pipapi] requirements=["yaml"] use_online_index = true it is working. In VS Code Plyance can not resolve this depencency. tl;dr Thank you for your hints on how to to inculde external dependencies installed via pipapi also for Pylance.
🌐
GitHub
github.com › microsoft › pylance-release › issues › 3035
"Import could not be resolved" for local packages and modules · Issue #3035 · microsoft/pylance-release
July 8, 2022 - highlighting local imports with a wavy underline with the message: Import "mypackage" could not be resolved
Author   dariush-bahrami
🌐
GitHub
github.com › microsoft › pylance-release › issues › 2288
Import could not be resolved problem in vscode pylance v2022.1.3 · Issue #2288 · microsoft/pylance-release
January 26, 2022 - Pylance extension in VSCode (running on Win10-64) reports problem: Import "requests.packages.urllib3.exceptions" could not be resolved from source
Author   shaishap
🌐
GitHub
github.com › microsoft › vscode-python › issues › 25099
Pylance Fails to Resolve Import from venv; Python Extension Uses Global Python for Helper Scripts · Issue #25099 · microsoft/vscode-python
May 21, 2025 - Since these scripts are run by the global Python, the information does not include the venv's site-packages, leading Pylance to incorrectly conclude firebase_functions is unavailable. The core issue seems to be why the Python extension defaults to global Python for these helper scripts despite a venv being configured. This might be thematically related to broader interpreter context issues like those discussed in GitHub issue #23448 for the vscode-python repository (though that issue focuses on multi-root workspaces, and this report is for a single-root setup).
Published   May 21, 2025
Author   Lukemendels
🌐
YouTube
youtube.com › framework
How to fix Import could not be resolved from source Pylance - YouTube
How to fix Import could not be resolved from source Pylance in this video tutorial I'll teach you how can you solve your pylance extension problem so guys fo...
Published   September 3, 2021
Views   160K
🌐
GitHub
github.com › microsoft › pylance-release › issues › 4873
Import Errors in Visual Studio Code with Python · Issue #4873 · microsoft/pylance-release
I've encountered a persistent issue in Visual Studio Code (VSC) where I'm experiencing import errors when trying to import one Python file into another. The error is indicated by a yellow underline beneath the import statement, and the Problems tab states: "Import File could not be resolved Pylance(reportMissingImports)".
Author   ghost