I will appreciate if someone could explain the differences (if any) between:
Highest level: you never should use pip install
to install to system (--system
, or on Linux distros where --user
isn't the default, omitting --user
) when things might conflict with your system whereas apt install
is pretty safe.
Explanation:
apt
is the package installation tool of your Linux distro. A Linux distribution these days is mostly the effort to offer a way to install packages in a way that works with each other without breaking – for example, if you're trying to install a library that libreoffice uses, but in a version incompatible with your libreoffice, your linux distro tool will tell you that sadly, to fulfill your command, it will have to uninstall libreoffice, because it wouldn't work with that version you're requesting.
The fact that you very rarely see that happen is an indication of how well modern Linux distros are doing here: typically, most of software that you can install using apt
works well together.
pip
, on the other hand, has no notion of what other software you have on your machine, which you might need. You tell pip to install something in a version that breaks your ability to even boot your system – it will go ahead and do that.
pip
is python-specific. It assumes that all there is on that machine that has something to do with Python is kind of "fair game" and can be dealt with arbitrarily. Frankly, that is almost never the case – for example, on Fedora (another Linux distro that you're not using), you can easily break the installation tool dnf
(Fedora's apt
, if you will) with pip
.
So, why does pip
still exist? Well, there are situation where it's OK for pip to assume every bit of python it sees is under its control: Python brings a mechanism called virtual environments. In these, no python modules are per se installed, and they don't conflict with other software on your machine – simply because other software isn't aware of the environment.
Using that is quite straightforward. You can set up such an environment using
python3 -m venv ~/bertsexperiment
That sets up a folder ~/bertsexperiment
for Python stuff to be installed into. You can then, from anywhere you like, "activate" that environment (what that really does is just change a few environment variables) – but that only affects the current process and things started from it. Try it:
source ~/bertsexperiment/bin/activate
will set up this shell in a way that all future python tooling will work with that folder as "prefix".
For example, if you wanted to have an updated setuptools in that shell, you could, after source
ing the activaton script as shown above, run pip3 install --upgrade setuptools
, and they would be installed into the virtualenv.
In short:
- if in doubt, use
apt
, because it's your distro's job to keep your software stack working together
- Never use
pip
unless you intend to install something into a folder only used for your current project and not by anything else on your system.
Hence, the only realistic time you would want to use it is when you're using a Python virtualenv.