1

I am relatively new to Python so please pardon my ignorance. I want to know answer to following questions

  1. How does pip know the location to install packages that it installs? After a built of trial and error I suspect that it maybe hardcoded at time of installation.
  2. Are executables like pip.exe what they call frozen binaries? In essence, does it mean that pip.exe will run without python. Again after a bit of trial and error i suspect that it requires a python installation to execute.

P.S: I know about sys.prefix,sys.executable and sys.exec_prefix. If there is anything else on which the questions i asked on depends, pls link me to same.

user83335
  • 31
  • 4
  • "pip.exe" is only a small stub to load the actual interpreter from "PythonXX.dll" (XX means the Python version number) and run the pip Python code from standard library with it. – Michael Butscher Apr 15 '20 at 11:04
  • and tne path to find this python.dll must be hardcoded in pip.exe right? because when i replace pip.exe that comes with python with pip.exe of a virtual env i create it shows error along the lines of "cant find python on virtual environment's path" ( i delete the created virtual env after i replace default pip with virtual env's ) pip. – user83335 Apr 15 '20 at 11:24

2 Answers2

1

PIP is a package manager for Python packages, or modules if you like.

pip when used with virtualenv will generally install packages in the path /lib//site-packages.

For example, I created a test virtualenv named test, and the django folder is in test/lib/python3.7/site-packages/django.

At the time of installation, you must have set up environment variables, and that is how pip recognizes directories.

Amit Rautray
  • 176
  • 7
1

pip.exe which is placed under path\Scripts needs a python installation and can't run without one. It is hardwired against a specific python interpreter, and can't install packages for another one. If you have 7 different python versions installed on your system, you will also have 7 different versions of pip.

Since it is bound so tightly, pip was at some point even included with the python standard library (see pep-0453 for details).

This also answers the other part of your question of how pip figures out the right location - there is only one location it can install to, the side-packages of the python interpreter it is bundled against.

user83335
  • 31
  • 4
Arne
  • 17,706
  • 5
  • 83
  • 99
  • Thank you so much buddy...this is exactly what i was looking for :) – user83335 Apr 15 '20 at 11:52
  • Also, can u pls guide me as to where i can look up for such stuff if i have queries in future...like a good book or something... or i should look it up in documentation?Btw i tried to look at install.py code for pip on github but i was quite overwhelming to be honest – user83335 Apr 15 '20 at 11:57
  • 1
    The source code is probably the last resort to learn stuff like that =D Well, the python documentation in general is quite good, so lots of stuff can be learned there. For packaging, I reference the python packaging authority docs (for short pipa: https://pip.pypa.io/en/stable/user_guide/), and other stuff is mostly picked up by having worked with python for a while. – Arne Apr 15 '20 at 12:04
  • 1
    There is also [a python chat room](https://chat.stackoverflow.com/rooms/6/python) on stackoverflow that you can visit to learn stuff, and the users on there maintain a [good tutorials list](https://sopython.com/wiki/What_tutorial_should_I_read%3F). – Arne Apr 15 '20 at 12:09
  • Thank you so much..joined the room..also i read the docs and pipa docs as well but couldnt find answer so asked the questn here – user83335 Apr 15 '20 at 14:23
  • Arne, please check the edit and see if what i understood is correct – user83335 Apr 15 '20 at 16:48
  • 1
    @user83335 I don't really know, I rarely develop under windows, so I'm not familiar with the specifics there. I went ahead and accepted it, since it seems to answer a part of your question. – Arne Apr 15 '20 at 17:18
  • 1
    Fair...let it be..if in future someone using windows knows about it and sees we can hope he will point out if i misunderstood – user83335 Apr 15 '20 at 17:37