简体   繁体   中英

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM