hardik24
hardik24

Reputation: 1048

Pip installing packages in global environment instead of virtualenv on Windows

I am using pycharm and for that i am using python virtualenv.

I activate virtualenv using penv\Scripts\activate.bat command. But when i run pip install requests, it is getting installed in global folder instead of local virtualenv folder. I am not able to understand why is the case so.

Output of where python is as follow:

E:\app-backend\penv\Scripts\python.exe
C:\Users\Hardik\AppData\Local\Programs\Python\Python37\python.exe

Output of where pip is as follow:

E:\app-backend\penv\Scripts\pip.exe
C:\Users\Hardik\AppData\Local\Programs\Python\Python37\Scripts\pip.exe

I have tried it again and again but it always installs any package in global folder. But when I run any command using E:\app-backend\penv\Scripts\pip.exe install of pip, it installs that package in local virtualenv.

Can anyone tell me what is the case happening here?

Upvotes: 8

Views: 22130

Answers (2)

Vlad
Vlad

Reputation: 377

I know this is an old question, but adding this solution for anyone who will face this issue in the future. In my case the issue source was the fact that I moved the virtual env folder to a different location, so the path in activate was wrong. Basically for me the fix was:

  1. Opening activate.bat (for windows) and correcting the path for VIRTUAL_ENV (for mac would edit activate)
  2. After that need to call deactivate and activate again.

This fixed the issue for me. Hope helps someone.

Upvotes: 2

Alexis Milekhin
Alexis Milekhin

Reputation: 23

You should run python from your virtual enviromment. For example:

E:\app-backend\penv\Scripts\python.exe -m pip list

But you should activate your venv first:

E:\app-backend\penv\Scripts\activate

Upvotes: 0

Related Questions