When your operating system (in this case windows) searches for an executable when it's not given it's path (like pip
), it searches each of the directories in the PATH
environment variable for that executable (i.e. say you enter the command python3
when
PATH="C:\Python27\bin;C:\Program Files\git\bin;
C:\Program Files (x86)\Java\JDK\6.0\bin;C:\Python35\bin"
then the command line will search each of those directories for an executable name python3
. However, it won't find the executable until it searches the last directory, and then it will run C:\Python35\bin\python3.exe
.
When you install a virtual environment (venv, for short) a script is created called C:/path/to/my/venv/bin/activate.bat
which you can run to activate (what a surprise!) the venv. Among other things, that script prepends C:\path\to\my\venv\bin
to the PATH
(i.e. sets PATH="C:\path\to\my\venv\bin;$PATH
, where the dollar sign just means use the value of the PATH
variable.
Then, when you ran pip install requests
, the command line started to search the PATH for a pip executable. It tries entries in order, so it found pip.exe
in the C:\path\to\my\venv\bin
directory, so in fact you did inadvertently use C:\path\to\my\venv\bin\pip.exe
when you ran pip install requests
. More importantly, this is actua;;y one of the main purposes the activate.bat
script exists; this way, you don't need to specify the precise path to every executable you have installed in you venv instead of using C:\path\to\my\venv\bin\python
you can just use python
, so long as you activate the venv. If you never run C:\path\to\my\venv\bin\activate.bat
then the PATH
environment variable will be as it was in the beginning, and it will install packages globally (which is not what you want).