what does pip install actually do?

Derek Eden picture Derek Eden · Jul 22, 2019 · Viewed 7.8k times · Source

Super newb question here..

What does pip install actually do?

Assuming the pypi package is a tarball...

Does it just download the tar.gz, unpack it and run setup.py?

Does it add the downloaded package to the site_packages folder?

I want to create a pip installable pkg using pypiserver so my colleagues can download my pkg in a painless way, but am a little unsure exactly what to include beyond the actual .py scripts.

Any guidance would be appreciated

Answer

dkreeft picture dkreeft · May 27, 2020

The tar.gz file is a source archive whereas the .whl file is a built distribution. Newer pip versions preferentially install built distributions, but will fall back to source archives if needed. You should always upload a source archive and provide built archives for the platforms your project is compatible with. In this case, our example package is compatible with Python on any platform so only one built distribution is needed.

See: https://packaging.python.org/tutorials/packaging-projects/

You would typically not manually create the source archive and wheel, but use setuptools and wheel to do so for you.

Nowadays, many packages are wheels. While installing these wheels using pip, pip will:

[...] unpack the archive in your current site packages directory and install any console scripts contained in the wheel.

See: https://wheel.readthedocs.io/en/stable/user_guide.html#installing-wheels