I’m trying to install packages in a newly created virtual environment in VS Code. The environment is created and selected (highlighted in red in the below image) but pip
is installing packages in the global environment instead:
Looking at other questions on SO, most were because the global environment/interpreter were selected instead of the (newly created) virtual environment.
Do I need to "activate" the environment separately? VS Code documentation doesn’t mention this and I’m assuming it is automatically activated at creation.
2
Answers
In order to install packages in your environment you need to first activate it. To activate it you can use the command in the terminal:
.venvScriptsactivate
You know it worked if there is a
(.venv)
at the start of the path in the terminal.If you want more information you can check the guide on how to install packages in virtual environment using pip and venv
Hopefully this helps solve your issue.
A relatively easy way to do this is:
Run Python File
button on the top right. VSCode will active the venv environment for you automatically.pip install packageName
command in the terminal.Hope this can help.