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

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
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
'Import "Path.to.own.script" could not be resolved Pylance (reportMissingImports)' in VS Code using Python 3.x on Ubuntu 20.04 LTS - Stack Overflow
It is a similar situation I'd encountered several months ago using pylint prior to pylance: My python 3.9x - script (using VS Code on Ubuntu 20.04 LTS) starts with the following import of custom &q... More on stackoverflow.com
🌐 stackoverflow.com
"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
🌐
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.
🌐
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.
🌐
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.
🌐
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
🌐
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 - You can activate it manually or set up VSCode to automatically activate it. Double-check that pandas is installed in your virtualenv. Run pip list in the terminal to verify. Pylance might not be configured to recognize your virtualenv.
Find elsewhere
🌐
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 › 3035
"Import could not be resolved" for local packages and modules · Issue #3035 · microsoft/pylance-release
July 8, 2022 - Start port is 9000 info 17:35:41.66: Process Execution: > ~\miniforge3\envs\myenv\python.exe -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)" > ~\miniforge3\envs\myenv\python.exe -c "import ipykernel; print(ipykernel.__version__); print("5dc3a68c-e34e-4080-9c3e-2a532b2ccb4d"); print(ipykernel.__file__)" info 17:35:41.99: Creating daemon process for c:\Users\dariush\miniforge3\envs\myenv\python.exe with env variables count 64 info 17:35:41.103: Process Execution: > ~\miniforge3\envs\myenv\python.exe -m vscode_datascien
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.
🌐
Visual Studio Code
code.visualstudio.com › docs › python › editing
Editing Python in Visual Studio Code
November 3, 2021 - This Quick Fix displays a quick pick menu that enables you to search for import options that prefix-match the missing import symbol. Pylance displays the Change spelling Quick Fix on unresolved variables or missing imports diagnostics when they ...
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.
🌐
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
🌐
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
🌐
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