You could select your python interpreter in VSCode by shortcuts "Ctrl+Shift+P" and type "Python: Select Interpreter" and choose the python interpreter which you installed the package in.

If it still not work, you could run command pip install pytest in the terminal to install the package in the current interpreter.

Answer from MingJie-MSFT on Stack Overflow
🌐
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.
🌐
Reddit
reddit.com › r/learnpython › vscode and pytest not recognizing imports
r/learnpython on Reddit: VSCode and pytest not recognizing imports
April 19, 2025 -

So I'm migrating my code to a new project format after learning about how they should be formatted for release. I'm using UV to create the .git-ignore and all the other goodies it does. The package is called cmo. I'm trying to run tests on some of the code and resolve imports.

So as an example: I have cmo/src/data/doctrine/air_operations_tempo. And I have a file cmo/src/helpers/values/get_item_from_menu with the function get_item_from_menu.

air_operations_tempo imports it but is getting an error that neither com/src/etc. nor src/helpers/etc. work as a valid import path.

Also, trying to import air_operations_tempo into cmo/tests/data/doctrine/test_air_operations_tempo doesn't work either with cmo/src/etc. nor src/data/etc.

I am at a loss it works on the old code but not anymore. Any help would be GREATLY appreciated. I am at wits end. It's probably something simple knowing my luck.

A picture of the file structure

🌐
Stack Exchange
devops.stackexchange.com › questions › 16370 › vscode-pytest-gives-me-an-error-when-importing
python - Vscode/pytest gives me an error when importing - DevOps Stack Exchange
August 2, 2022 - When I write an import line like this from mypackage import something and run it using vscode tools it gives my an error, when I run it using venv python it works. Same for pytest, I have to run it like this: python3 -m pytest tests for it to work.
🌐
freeCodeCamp
forum.freecodecamp.org › python
Pytest Installed, but VS Code Won't Access Pytest - Python - The freeCodeCamp Forum
September 12, 2023 - Hi, I’m starting to learn how to write tests for my code. I’ve installed pytest on my device using pip. But VS Code won’t access it. I assume it’s something to do with the path. I’ve tried using different IDEs, but I…
Find elsewhere
🌐
GitHub
github.com › microsoft › pylance-release › issues › 236
Import "[module]" could not be resolvedPylance (reportMissingImports) · Issue #236 · microsoft/pylance-release
August 13, 2020 - 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.
Author   jiangzhuochi
🌐
GitHub
github.com › microsoft › pylance-release › issues › 4873
Import Errors in Visual Studio Code with Python · Issue #4873 · microsoft/pylance-release
The issue persists even with a fresh installation of Python and VSC, and with all Python-related folders deleted. The code runs without any import errors in PyCharm. The import statement works to import a function or class, but it is labeled as a defect import, and pytest does not detect it unless it is testing right out of the file.
Author   ghost
🌐
Python Forum
python-forum.io › thread-40713.html
Pytest Installed, but VS Code Won’t Access Pytest
September 12, 2023 - Hi, Sorry, I understand questions about installing packages and problems with path directories are common, but I've tried everything and really need help. I’m starting to learn how to write tests for my code. I’ve installed pytest on my device...
🌐
GitHub
github.com › microsoft › pylance-release › issues › 1020
Installed packaged not being 'resolved' - Brownie and PyTest · Issue #1020 · microsoft/pylance-release
March 7, 2021 - import brownie from brownie import accounts, Farm import pytest pylance doesn't recognize these libraries though the warning is ignored and compiles correctly as these are all up to date on my ...
Author   liam-ot
🌐
YouTube
youtube.com › framework
How to fix Import could not be resolved from source Pylance - YouTube
How to fix Import could not be resolved from source Pylance in this video tutorial I'll teach you how can you solve your pylance extension problem so guys fo...
Published   September 3, 2021
Views   160K
🌐
Reddit
reddit.com › r/vscode › cannot get pytest to work with vscode
r/vscode on Reddit: Cannot get pytest to work with VSCode
November 25, 2019 -

I am trying to get pytest to work. I am using VSCode, Anaconda and the Python extension on Windows 10 (all latest versions) with:

  • pytest 5.2.4.

  • Python 3.7

I am probably using the second most simplest use case. I have all my test files in a subdirectory called tests in the root directory of my application source code.

I can get test discovery and execution to work when I am at a command prompt with the activated anaconda environment and type: python -m . Pytest discovers all the tests and runs them with no problems whatsoever.

If I click on the Test discovery in VSCode, pytest finds all the test files but there are all kinds of ModuleNotFoundError errors. Example error output:

_____________________ ERROR collecting tests/test_acsr.py _____________________
ImportError while importing test module 'C:\path_to_source_code\tests\test_acsr.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
tests\test_acsr.py:6: in <module>
    from acsr import is_pure_ground_run
E   ModuleNotFoundError: No module named 'acsr'

The acsr.py file is in the root of my application (parent directory of tests) and contains the functions I wish to test.

I checked the VS Code, and pytest documentation to see if I was missing some configuration options but didn't find anything. It appears that under VS Code, pytest can't figure out the sys.path or something. I feel like I am going around in circles trying to get this working as none of the answers on stackoverflow or anywhere else seem to fit this simple use case.

If anyone can supply me with a fix or has a link to a comprehensive tutorial that helps with pytest setup in VS Code I would be greatly appreciated.

PS I had it working in VS Code months ago, and I don't remember having to do any special configuration beyond what was outlined in the docs. It just stopped working one day, perhaps after an update, not sure. When it was working I thought it was pretty awesome.

🌐
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 - 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.
🌐
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 - I have this line in my py source code (Python 3.10.1 64-bit): from requests.packages.urllib3.exceptions import InsecureRequestWarning Pylance extension in VSCode (running on Win10-64) reports problem: Import "requests.packages.urllib3.ex...
Author   shaishap
🌐
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 › vscode-python › issues › 19556
VSCode cannot detect pytest unit tests, even pytest has been installed, error comes from inside .vscode-serve folder, behind company's proxy · Issue #19556 · microsoft/vscode-python
July 26, 2022 - VSCode cannot detect pytest unit tests, even pytest has been installed, error comes from inside .vscode-serve folder, behind company's proxy#19556
Author   franva
🌐
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 - @Krishnamohan Nadimpalli Thanks for reaching out. 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.
🌐
GitHub
github.com › microsoft › vscode-python › issues › 9450
Cannot discover with pytest in 2020-01 · Issue #9450 · microsoft/vscode-python
January 8, 2020 - The base environment does not have pytest installed, using a different environment with pytest installed I get the following output: python c:\Users\Federico\.vscode\extensions\ms-python.python-2020.1.57204\pythonFiles\testing_tools\run_adapter.py discover pytest -- --rootdir c:\Users\Federico\Documents\GitHub\pytest-error -s --cache-clear Test Discovery failed: Error: The system cannot find the path specified.
Author   CaselIT