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.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.
Install
sqlalchemyandmongoenginewith commandpip 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.
I'm trying to use torch in a python script but even though it's pip installed, pylance doesn't recognize it
https://imgur.com/EM5fEIo
Any advice on how to resolve this? Thanks.
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.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.
Install
sqlalchemyandmongoenginewith commandpip 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.
To resolve the issue, perform the following steps:
- Open the Command Palette by pressing Ctrl+Shift+P on your keyboard.
- In the Command Palette, select Python: Clear Cache and Reload Window.
python - VS Code / Pylance / Pylint Cannot resolve import - Stack Overflow
Import "[module]" could not be resolvedPylance (reportMissingImports)
Why Python imports cannot be resolved by Pylance in VS Code, if the package is located in a shared folder? - Stack Overflow
Pylance: import from same directory could not be resolved
Videos
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.
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
xthen runninghelp(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.
You can add the following codes to your settings.json to solve this problem:
"python.analysis.extraPaths": [
"path/to/your/packages"
],
I faced the same error some days ago. This is how I fixed it.
- Copy the path to your Python interpreter in your virtual environment folder.
- Press
Ctrl+Shift+Pto open command pallete. Choose thePython: Select Interpreter - Choose
Enter Interpreter Path - Paste the path you copied. So it should look like
./<Project_Folder>/env/bin/python. ClickEnter
And it's solved.
Pylance, by default, includes the root path of your workspace. If you want to include other subdirectories as import resolution paths, you can add them using the python.analysis.extraPaths setting for the workspace.
- In VS Code press
<ctrl> + <,>to open Settings. - Type in
python.analysis.extraPaths - Select "Add Item"
- Type in the path to your library
/home/andylu/Dokumente/Allgemeines_material/Sonstiges/Programming/Python/Scripts/
Two methods below:
In VS code you can edit the
setting.jsonfile. If you add"python.analysis.useImportHeuristic": truethe linting error will be removed.The alternative is to add
# type: ignoreat the end of the import code.
Here is the github link that i got the above resolution from: https://github.com/microsoft/pylance-release/issues/68
It worked for me: python 3.9, VScode, windows10