skip to Main Content

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:

enter image description here

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


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

    Login or Signup to reply.
  2. A relatively easy way to do this is:

    1. Use shortcuts Ctrl+Shift+P and type "Python: Select Interpreter" to choose your venv environment as the current python interpreter.
    2. Click the Run Python File button on the top right. VSCode will active the venv environment for you automatically.
    3. Use pip install packageName command in the terminal.

    Hope this can help.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search