Search code examples
pythonpowershellpipvirtualenv

Python packages keep installing to local drive instead of project's virtual environment using pip from terminal


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!


Solution

  • activate.bat is only compatible with cmd.exe.

    When you're using PowerShell, you want to use activate.ps1 instead -- or just invoke activate and let the shell select an appropriate implementation.