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
Discussions

Import could not be resolved in VS Code
I am trying to write a code in Azure Functions through VS Code, but in import it says "Import could not be resolved". Following is screenshot Python is installed, Azure Storage Account is installed Do I need to put them in some… More on learn.microsoft.com
🌐 learn.microsoft.com
1
0
November 17, 2022
"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
flask - Import could not be resolved/could not be resolved from source Pylance in VS Code using Python 3.9.2 on Windows 10 - Stack Overflow
My Flask App server is running but I have three imports that cannot be resolved. I have tried: reinstalling the imports individually reinstalling requirements.txt I configured VSCode Workspace wi... More on stackoverflow.com
🌐 stackoverflow.com
Visual Studio 2022 import xyz could not be resolved from the source
I upgraded Visual Studio 2022 Enterprise version 17.4.4 I loaded the python project previously configured by Visual Studio 2019. Visual Studio 2022 keeps complaining about Python libraries set up in virtual environment. The virtual environment was… More on learn.microsoft.com
🌐 learn.microsoft.com
0
0
March 20, 2023
🌐
GitHub
gist.github.com › krisbolton › 20159d66f1d919c9c2380c96b6ac3915
VSCode import could not be resolved by Pylance (reportMissingImports) · GitHub
Visual Studio Code (VSCode) reports an error (yellow squiggly lines) saying "Import [nameOfModule] could not be resolved by Pylance (reportMissingImports)". You may be using a virtual environment (e.g., venv).
🌐
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.
🌐
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 ...
🌐
GitHub
github.com › microsoft › pylance-release › issues › 4873
Import Errors in Visual Studio Code with Python · Issue #4873 · microsoft/pylance-release
Changed the Python Language Server to Jedi in the settings.json file, and back after it became apparent it didn't cause the issue. Compared the current working directories in different environments using os.getcwd() to ensure they are the same. Cleared Cache and Extension Data. Added an init.py file to the directory, with no result. Tried using relative import from .file2 import my_function, with no result.
Author   ghost
🌐
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.
Find elsewhere
🌐
k0nze
k0nze.dev › posts › python-relative-imports-vscode
Python Relative Imports in VSCode (Fix ModuleNotFoundError and Auto-completion) | k0nze
January 30, 2024 - Then the project structure could look like this: 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.
🌐
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 · Note: in the provided screenshot, it is clear that this is a problem with the notebook, not the python extension in general. ... Visual Studio Code (1.69.0, undefined, desktop) Jupyter Extension Version: 2022.6.1001902341.
Author   dariush-bahrami
🌐
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 I'm getting this error just on requests , not on anything else. My interpreter is selected correctly from what I can tell and always has been. The code runs fine from within VSCode too. ... Looks like adding c:\program files\python310\lib\site-packages to analysis.extraPaths did the trick for me.
🌐
Position Is Everything
positioniseverything.net › home › python unresolved import: 5 causes and their solutions
Python Unresolved Import: 5 Causes and Their Solutions - Position Is Everything
December 29, 2025 - Visual Studio Code can find your Python module if you do any of the following: ... Updating your default Python interpreter will solve the “Python import could not be resolved pylance” and “vscode not recognizing python” errors.
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 1191390 › visual-studio-2022-import-xyz-could-not-be-resolve
Visual Studio 2022 import xyz could not be resolved from the source - Microsoft Q&A
March 20, 2023 - Visual Studio 2022 keeps complaining about Python libraries set up in virtual environment. The virtual environment was configured in Visual Studio 2019 and works in Visual Studio 2019 perfectly. In general, Visual Studio 2022 says import xyz could not be resolved from the source, where xyz could be library such as pandas or sqlarchemy
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/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.

🌐
Python Forum
python-forum.io › thread-37465.html
Problem with importing Python file in Visual Studio Code
June 14, 2022 - Hello here ! I'm learning how to code starting with Python, and I'm facing a problem trying to import a file as a module. With this code : import os import sys sys.path.append(os.getcwd()+'\launch') import launch as lI'm getting the issue 'Import 'l...
🌐
Medium
medium.com › nerd-for-tech › import-errors-in-python-no-module-named-module-name-for-vs-code-887d1f78cf02
Import Errors in Python: No Module Named “Module_Name” For VS Code | by Dilmi Kottachchi | Nerd For Tech | Medium
June 12, 2021 - In this case it ‘Python 3.9.2 64 bit (‘venv’: conda)’ as shown below. ... Once you selected that, you will see that your interpreter has shifted to point to your virtual environment. ... So there you have it. Once you run your project, everything will be working fine and no more import errors you will have to worry about.
🌐
GitHub
github.com › microsoft › vscode-python › issues › 21456
Improve messaging when an import could not be resolved · Issue #21456 · microsoft/vscode-python
June 20, 2023 - To address some of the confusion around environments and package installation, we should provide specific Code Actions and/or specific messaging tailored for users that are not using an environment with their specified packages or struggle to resolve import errors. ... Link to documentation (We don’t specifically have documentation on import errors. Should we create a new page or add this to an existing one?) https://code.visualstudio.com/docs/python/environments https://code.visualstudio.com/docs/python/editing#_troubleshooting-intellisense
Author   cwebster-99
🌐
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'm getting this weird thing in vscode where my import is working properly but theres a yellow line under the module name and when I hover over that, it says module can't be resolved.

If I try and change how I access the module (using a relative path, perhaps), the yellow error line is no longer there but the code doesn't work as python or vscode doesn't recognise the module name/path

Does anyone have experience with this?

My code works but the yellow line is annoying.

I don't NEED to separate my code into different files but it would still be good to know what's going on here

Thank you

🌐
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…