The most popular Python package manager, pip, used to be included in a typical Python install, but lately it's been excluded. Pip is a useful tool for both running Python scripts and for developing them, and it's easy to install. There are just two steps to install pip on Linux:
1. Get the installer
Now that you've install pip, you might want to know more about what it's good for. Here are some basic used of the `pip` command.
Install dependencies {#_install_dependencies}
When you download a Python script or an application written in Python, it may require specific Python libraries (or "modules", in Python terminology) in order to run. An application may not bundle support libraries along with its own code because the library isn't maintained by the same developer. Were it bundled along with unrelated application code, it would be difficult for you to update it independently of the application.
Usually, a developer includes a list of dependencies in a file called `requirements.txt` in the application directory. If that file exists, you can process it with pip:
$ python3 -m pip install -r requirements.txt
If the developer hasn't included a list of dependencies, then it's up to you to read the documentation to learn the what dependencies are required.
If you install software with
dnf
or
Flatpak
, you may never have to use pip for this, because those packaging systems install dependencies automatically.
Install a Python utility {#_install_a_python_utility}
You can use pip for quick installs of useful Python utilities. For instance, `yamllint` is a must-have command for anyone writing
YAML
files, whether it's for Kubernetes or
Ansible
or just for arbitrary config files. It's one `pip` command away:
$ python3 -m pip install yamllint
Or maybe you want to try the
Ranger
file manager:
$ python3 -m pip install ranger
There's a lot out there for Python, so have a look at
Python Package Index (PyPi)
to see what's available.
See installed packages {#_see_installed_packages}
To see what Python packages you've already got installed, use the `freeze` command:
$ python3 -m pip freeze
Brlapi==0.8.2
chardet==4.0.0
chrome-gnome-shell==0.0.0
cupshelpers==1.0
dasbus==1.4
dbus-python==1.2.18
gpg==1.15.1
idna==2.10
[...]
Using pip {#_using_pip}
Pip works well for both users without root access and developers using Python virtual environments. It's an easy command to use, and it helps you manage your Python install.