A missing-library error in VS Code usually means the editor and the terminal are using different Python interpreters. Installing a package into one environment does not make it available in another.
Open the Command Palette and choose Python: Select Interpreter. Pick the virtual environment for the project. Then open a new terminal so the selected environment is activated. Confirm the path with python -c "import sys; print(sys.executable)" and check installed packages with python -m pip list.
Install the library through the interpreter you intend to run:Copy
python -m pip install package-nameUsing python -m pip is safer than a standalone pip command because it ties pip to the selected interpreter. If the import still fails, compare the package’s installation name with its import name. For example, a distribution and its Python module do not always use identical spelling.
Check the project’s .venv folder, workspace settings, and requirements.txt or pyproject.toml. Avoid installing packages globally just to silence one editor warning. Recreate the environment when it has become inconsistent, then reinstall dependencies from the project’s lock or requirement file.
Finally, reload VS Code if IntelliSense is stale. The goal is alignment: one project, one interpreter, one dependency definition.