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
🌐
GitHub
github.com › microsoft › pylance-release › issues › 519
Pylance cannot resolve the import of a local .py file · Issue #519 · microsoft/pylance-release
October 25, 2020 - Environment data Language Server version: 2020.10.2 OS and version: W10 Version 1903 Python version: 3.7.5 64-bit Expected behaviour When importing a local python script instead of a module, Pylance should be able to read the methods def...
Author   egeres
Discussions

"Import could not be resolved" for local packages and modules
Environment data VS Code version: 1.69.0 Jupyter Extension version (available under the Extensions sidebar): v2022.6.1001902341 Python Extension version (available under the Extensions sidebar): v2... More on github.com
🌐 github.com
9
July 8, 2022
Import could not be resolved [Pylance]
Try to Reload Window. If the error still exists, check if you install the module in your selected interpreter environment. More on reddit.com
🌐 r/vscode
12
14
June 23, 2021
Local imports not resolving correctly
Environment data Language Server version: 2020.6.1 OS and version: Windows 10 Version 10.0.18363 Build 18363 Python version (& distribution if applicable, e.g. Anaconda): Python 3.8.2 32bit Exp... More on github.com
🌐 github.com
82
July 7, 2020
visual studio code - How can I import a local python file? it's currently giving an import cannot be resolved pylance error - Stack Overflow
from dinocore import Object, grabScreen dinocore is the name of my other local Python file, it's in the same folder. So far I've tried moving the files around into different folders, but that hasn't More on stackoverflow.com
🌐 stackoverflow.com
🌐
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 › 3035
"Import could not be resolved" for local packages and modules · Issue #3035 · microsoft/pylance-release
July 8, 2022 - To read more about this, see https://github.com/ipython/ipython/issues/2049 To connect another client to this kernel, use: --existing c:\Users\dariush\AppData\Roaming\jupyter\runtime\kernel-v2-16040HnxfnN5XtDwc.json info 17:35:43.32: Started kernel myenv (Python 3.10.5)., (Raw session started and connected) info 17:35:43.33: Finished connecting 77698eb3-0340-4306-ac43-d152a89a6550 info 17:35:43.34: UpdateWorkingDirectoryAndPath in Kernel info 17:35:43.34: Executing silently Code (idle) = import os\nimport sys\n� "d:\projects\bugs"\nif os.getcwd() not in sys.path:\nsys.path.insert(0, o info 1
Author   dariush-bahrami
🌐
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.
🌐
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
🌐
Sentry
sentry.io › sentry answers › vs code › fix pylance resolvemissingimports in vs code
Fix Pylance resolveMissingImports in VS Code | Sentry
July 15, 2024 - If you previously installed fastapi to the virtual environment, the resolveMissingImports error should now disappear. Otherwise, run pip install fastapi in your terminal before attempting to run your Python script. Configure VS Code to automatically activate the virtual environment for your current project in its embedded terminal by following these steps: Navigate to File > Preferences > Settings.
🌐
GitHub
github.com › microsoft › pylance-release › issues › 68
Local imports not resolving correctly · Issue #68 · microsoft/pylance-release
July 7, 2020 - main.py and emailRelay.py are in the same directory, and I am importing emailRelay.py into main.py), the import should not be linted unless file I am importing does not exist. When trying to import another python file from the same directory as the current file (e.g. main.py and emailRelay.py are in the same directory, and I am importing emailRelay.py into main.py), Pylance lints it as an unresolved import
Author   aaronsmith1234
🌐
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
🌐
GitHub
github.com › microsoft › pylance-release › issues › 7618
Pylance fails to resolve imports from site-packages when local src/ uses same namespace · Issue #7618 · microsoft/pylance-release
October 7, 2025 - Root Cause: Pylance gets confused when there's a local src/zope/ namespace directory and tries to resolve zope.interface within the local namespace instead of falling back to site-packages where zope.interface is actually installed.
Author   wesleybl
🌐
YouTube
youtube.com › programmingknowledge2
How To Fix Import Could Not Be Resolved From Source Pylance - YouTube
Welcome to this tutorial on how to fix "Import could not be resolved from source" Pylance error.Pylance is a powerful language server that provides advanced ...
Published   May 15, 2023
Views   43K
🌐
CopyProgramming
copyprogramming.com › howto › vs-code-pylance-pylint-cannot-resolve-import
VS Code Pylance Pylint Cannot Resolve Import: Complete Guide & 2026 Best Practices - Code pylance pylint cannot resolve import complete guide
December 11, 2025 - The "Import could not be resolved" ... configuration adjustments. This error occurs when Pylance—Microsoft's advanced Python language server extension—cannot locate the module you're attempting to import, even though the code runs perfectly when executed....
🌐
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.
🌐
GitHub
github.com › microsoft › pylance-release › issues › 1167
Pylance unable to resolve local import placed in the same directory · Issue #1167 · microsoft/pylance-release
April 17, 2021 - If my main source code is running in code/, it is impossible to import any of the local .py files from baseline/, utils/, foo/, ...
Author   jaepil-choi
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.