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.
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.
Videos
probably Pylance is having problems with the path for site-packages folder for your virtual environment and returns Import "pytest" could not be resolved, you need to set python path in this way:
"python.pythonPath": "/my/project/path/.venv/bin/python"
I tried h. deville fletcher's answer and it didn't seem to work for me, but I could have messed up in there too. However, in the process, I remembered that I hadn't changed my interpreter. Once I changed the interpreter to my pipenv shell that fixed my problem.
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.
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
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.