A few days ago I was installing a development environment for django on ubuntu 18.04. However when I installed pip a question came up. What is the difference between using pip from the deadsnakes python installation or using it when installing it from apt install python-pip?
2 Answers
Depending what apt install python-pip does. Hopefully there is no difference because PIP just uses the Python as the interpreter to install Python packages depending on the Python installation path. You can use it in virtual envs or installing packages to the global system.
- 103
- 4
Debian/Ubuntu patches the CPython interpreter and some standard libraries to make them compatible with some Debian/Linux/Posix standards. I think the main issue is that of being "compliant" with FHS, like explained here. Those patches change the default install location of Python packages and other things. Another characteristic of Debian/Ubuntu Python distributions is that some stdlib modules are only partially provided or not provided at all (like distutils and venv), needing to install it separately from the official repositories using apt (not pip):
$ sudo apt install python3-lib2to3 python3-disutils python3-venv
Following the same, Ubuntu Python doesn't come with pip nor ensurepip, instead they provide the python3-pip package, the patched version of the standard pip, altering it's standard behavior so as to follow those install location modifications. This packaging guide also says that python3-pip uses User Schema by default while pip doesn't.
deadsnakes PPA doesn't have a great documentation but follows the same path:
The packages provided here are loosely based on the debian upstream packages with some modifications to make them more usable as non-default pythons and on ubuntu.
deadsnakes also provide a python#.#-venv package to replace the python3-venv (also provide replacements for the python3-<dev/distutils/lib2to3/gdbm/tk>).
deadsnakes' Python doesn't come with neither pip or ensurepip and doesn't provide a python#.#-pip, so in order to install packages directly in the Python local installation you would need the python3-pip (don't install/use the standard pip, since it wont know about the correct install locations):
To install 3rd-party Python modules, you should use the common Python packaging tools.
But this isn't recommended. You should keep the local Python clean and packages should be installed in a virtual environment using the python#.#-venv that deadsnakes provide, which bootstraps (not 100% sure) the standard pip. I also tested python#.# -m venv --system-site-packages venv and apparently the environment worked just fine using also the user locally installed packages (at /usr/local/lib/python#.#/dist-packges).
PS 1: Filipe Laíns linked post in old (from 2021) and my WSL2's Ubuntu 22.04 (jammy) system Python apparently comes with a sysconfig patch.
PS 2: Python user experience is bad in Debian distros, and a lot of headaches can be avoided building CPython from source as an alternative Python installation at /usr/local/bin.