Visual Studio 2022 import xyz could not be resolved from the source

Gui, Feng 21 Reputation points
2023-03-20T14:03:32.87+00:00

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

However, I could run the Python project in Visual Studio 2022 in debug mode without any problems.

I followed advice from https://stackoverflow.com/questions/68486207/import-could-not-be-resolved-could-not-be-resolved-from-source-pylance-in-vs-cod

I tried to activate the virtual environment as the post suggested. But it does not work.

Please let me know what I can do to remove the annoying warnings in Visual Studio 2022.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,103 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.