The accepted answer won't fix the error when importing own modules.

Use the following setting in your workspace settings .vscode/settings.json:

"python.autoComplete.extraPaths": ["./path-to-your-code"],

Reference: Troubleshooting, Unresolved import warnings

UPDATE 2023

As mentioned by shmim python-language-server is deprecated and new closed source LSP Pylance's setting is configured as follows:

"python.analysis.extraPaths": ["./path-to-your-code"]
Answer from Shinebayar G on Stack Overflow
🌐
GitHub
gist.github.com › krisbolton › 20159d66f1d919c9c2380c96b6ac3915
VSCode import could not be resolved by Pylance (reportMissingImports) · GitHub
In VSCode open settings by pressing ctrl + , and a search box will appear. Search for and select "pylance". Find the "Extra paths" item. Press the "add item" button and copy & paste the path you found in step 3. The squiggly lines and the error should have gone. Pylance now knows where to find the module you were attempting to import. N.b. you can exit the python interpreter by typing exit().
🌐
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 - Choose the interpreter from your virtualenv. Make sure your virtualenv is activated in the terminal you're using within VSCode. You can activate it manually or set up VSCode to automatically activate it.
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 1093387 › import-could-not-be-resolved-in-vs-code
Import could not be resolved in VS Code - Microsoft Q&A
November 17, 2022 - For your first issue Import could not be resolved in VS Code for pandas it will resolve once the panda is installed on your function environment locally. Please make sure that you are adding all the dependencies in requirement.txt file for any ...
Top answer
1 of 7
73

The issue was indeed with Pylance. It was missing an "additional path" to where pip had installed the projects I wanted to import. To solve the issue:

First make sure you know the location of your import; you can find it with:

$ python
>>> import modulename
>>> print(modulename.__file__)

Then, once you know the location:

  1. Open settings (ctrl + ,)
  2. Search "pylance" or find it under "Extensions > Pylance"
  3. Find the "Extra Paths" config item
  4. Use "add item" to a add a path to the parent folder of the module. It will not do any recursive tree searching

And you should be good to go!

For a further example, you can see the image above where I had added the path /home/seph/.local/lib/python2.7/ to no avail. Updating it to /home/seph/.local/lib/python2.7/site-packages/ did the trick.

2 of 7
24

I had a similar problem in my setup as I create a virtual environment per project and install Jupyter there. Instead of a global setting change in the Pylance extension, I rather prefer to follow what states its troubleshooting guide.

Suppose your virtual environment is called venv and it is inside your project folder:

  • Create a folder called .vscode at the root of your project folder, if it does not already exist. Don't forget the dot in front of the name.
  • Create or edit the file .vscode/settings.json and include this tag:
{
    "python.analysis.extraPaths": ["./venv"]
}
  • Note that the path to your virtual environment is relative to the root project folder, not the folder containing the settings.json file.

I hope this helps.

🌐
Reddit
reddit.com › r/learnpython › vscode saying import could not be resolved but it definitely is
r/learnpython on Reddit: vscode saying import could not be resolved but it definitely is
July 9, 2021 - I am running a python script from the command line (cmd) that is in a directory in the system PATH environment variable, and so it is able to import a module in that same directory. But I guess vscode doesn't know I'll be running the script there.
🌐
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.
Find elsewhere
🌐
LinuxPip
linuxpip.org › fix-python-unresolved-import-in-vscode
Fix Python Unresolved Import in VSCode – LinuxPip
March 1, 2022 - Given the example project structure below: ... In this newly-created, empty .env file, add the line PYTHONPATH=/path/to/module (replace /path/to/module with the actual module you’re trying to import). In this case, we have to replace /path/to/module with my_code to make Python import module from my_code · Then, to make sure that VSCode recognizes the .env file, place an additional "python.envFile": "${my_project}/.env" line to the settings.json, similar to how we did in the previous section of this article.
🌐
Python.org
discuss.python.org › python help
Import PyQt6,QtCore could not be resolved in VSCode - Python Help - Discussions on Python.org
April 10, 2024 - if I run my Python code in Idle it runs but all the menu items are missing (presumably because they came from PyQt. Running it in vsCode shows the import PyQt6.QtCore (also .QtGui and .QtWidgets) underlined in red in th…
🌐
YouTube
youtube.com › watch
How to Fix Import Errors in Visual Studio Code - Solve Python Import VSCode - YouTube
🚀 How to Fix Import Errors in Visual Studio Code | Solve Python Import Issues in VS Code (2025)Are you facing import errors in VS Code while running your Py...
Published   February 17, 2025
🌐
CodeForge Studio
6857simon.csail.mit.edu › home › youknowit › fix import could not be resolved error in vscode python
Fix Import Could Not Be Resolved Error in VSCode Python - CodeForge Studio
May 29, 2025 - The "Import Could Not Be Resolved" error typically occurs when the Python interpreter used by VSCode cannot find the module you are trying to import.
🌐
Reddit
reddit.com › r/vscode › help needed, import could not be resolved, but program works (python)
r/vscode on Reddit: Help needed, import could not be resolved, but program works (python)
July 28, 2023 -

I have been trying to learn python and it's going well I watched something on how to import from different folders my imports look like

import sys

sys.path.insert(1,"D:\programing\python\learn\book") from book import Book import booksSDK

Book is white text and it's normally green

booksSDK has a yellow squiggle

the program runs in fact there is nothing wrong with it, it does what it should no problems, but VScode complaining at me is driving me nuts.

under problems tab it says

import "booksSDK.py" could not be resolved Pylance(reportmissingimports) ln 4 col 8

the line it is citing is " import booksSDK"

thanks for the help this is kinda driving me a biit nuts

🌐
GitHub
github.com › microsoft › pylance-release › issues › 4873
Import Errors in Visual Studio Code with Python · Issue #4873 · microsoft/pylance-release
The import statement works to import ... it unless it is testing right out of the file. ... Ensured that there are no spaces or special characters in file and folder names. Ensured the correct Python interpreter is selected ...
Author   microsoft
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:

import 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:

import 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.
🌐
k0nze
k0nze.dev › posts › python-relative-imports-vscode
Python Relative Imports in VSCode (Fix ModuleNotFoundError and Auto-completion) | k0nze
January 30, 2024 - Now main.py can’t access MyClass using the import statement from above because libs/my_package is not in the folder that main.py is in, and when running main.py, the following ModuleNotFoundError is raised: There is a dirty fix to remove the ModuleNotFoundError by extending the PYTHONPATH inside of main.py.
🌐
Reddit
reddit.com › r/vscode › local python imports not recognized - "unresolved import"
r/vscode on Reddit: Local Python imports not recognized - "unresolved import"
May 17, 2020 -

I'm using the latest versions of VSCode, Python, and Python extension for VSC. I am running my code in a Virtual Environment as well.

Given an extremely simple folder structure like this:

\dev
 |_main.py
 |_other.py

from other import other in main.py is linting as "unresolved import 'other'" on the file name, i.e. the first "other".

The code however runs perfectly, so it isn't a syntax issue.

🌐
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   microsoft
🌐
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 - ... In my case, the fastest solution when imports are not missing is to launch vscode from the virtual environment. Basically, activate the venv as always, and then code . ... Thanks for the solution.