EDIT: See WORKAROUND in reply - if you get "unresolved import" on a package you have installed this might be the reason.
Even though VScode settings are set to use the venv interpreter, and the virtual environment is activated, when using pip or pip3 to install a package in the VSCode terminal, packages are installed into the default python directory.
e.g.
(.venv) person@MacBook-Pro my-code-lives-here % pip3 install python-dotenv
results after trying it twice so you can see the install path:
Requirement already satisfied: python-dotenv in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (0.15.0)
VS code settings.json:
"python.pythonPath": ".venv/bin/python3",
Same command was working last week as I have other packages installed.
question from:
https://stackoverflow.com/questions/66052734/python-pip-not-installing-package-into-the-correct-directory-in-virtual-environm 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…