skip to Main Content

currently, anytime I try to install python packages via pip commands in Visual Studio Code terminal, they are installing to my local drive instead of the virtual environment created within the project directory even when the virtual environment is activated. The virtual environment is also selected as the interpreter when referencing the lower right-hand corner of Visual Studio Code application window.

Does someone know what is causing this and how I can update this so that packages will install into the virtual environment Lib/site-packages directory instead of my local drive? I’ve checked multiple posts on here, but found nothing to resolve my issue. Recreating the virtual environments/upgrading pip did not do anything. I’m stuck at this point.

I tried a clean re-install of Python on my system to see if that would fix anything but the issue persists. I’m not sure why the python packages are installing to local drive instead of project virtual environment.. my best guess is that it could be something with the local drive version of pip being used for commands rather than in the venv, which is causing packages to be installed on the local drive instead?

Any help is much appreciated – thank you!

2

Answers


  1. This is working as intended I think. You need to activate the virtual environment to install packages to it. You need to execute the script under venv/Scripts/active (Windows and depending on your specific venv path), on Linux it’s similar.

    It is definitely badly designed, one alternative could be using a modern package manager such as poetry, there you don’t need to activate anything. There are also bleeding edge pip replacements such as uv, which by default don’t install packages globally.

    Login or Signup to reply.
  2. activate.bat is only compatible with cmd.exe.

    When you’re using PowerShell, you want to use activate.ps1 instead.

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