In this tutorial, we’ll go over the steps to install pip in Linux. The pip command allows us to install Python packages from the Python Package Index or PyPI.
The pip command can be installed with the package manager for your Linux distribution. In this tutorial, we’ll work with Ubuntu’s apt package manager to install pip.
What is Python PIP?
The pip command stands for Package Installer for Python. Similar to the apt command for Debian-based distributions, yum and rpm commands for Red Hat-based distributions, and pacman for Arch-based distributions, pip command helps install packages for Python.
When you’re working with Python, you can install the available packages using the system’s default package manager or work with pip to install Python-specific packages directly from their official index.
With the default package manager, there will always be packages that just aren’t available. But with pip, you can rest assured that most of the packages that you’ll require (and many more) will be available right there.
How To Install Pip In Linux?
So how do we go about installing pip in Linux? It’s really simple. Let’s walk through the simple steps to get pip up and running on our Ubuntu server here.
1 2 3 4 |
root@ubuntu:~# apt -y install python-pip OR root@ubuntu:~# apt -y install python3-pip <img class="alignnone wp-image-29587 size-full" src="http://all-learning.com/wp-content/uploads/2020/01/python3-pip-installation1.png" alt="python3-pip-installation" width="1200" height="628" /> |
If you’re using a different distribution of Linux, there’s nothing to worry about. Simply change the apt install part with your package manager.
For example, on an Arch-based system, you’d type
1 2 |
root@arch:~# pacman -S python2-pip root@arch:~# pacman -S python-pip #This installs python3 pip |
You can use python-pip (for python version 2) and python3-pip (for python version 3).
Depending on which version of Python you’re working with, you can install pip or pip3 and make sure that you have the right packages being installed.
How to Use PIP Command in Linux?
Now coming to the usage of PIP, we’ll learn how to
- install
- uninstall
- search
- list existing packages
- show details of a package
I’ve installed python3-pip on Ubuntu since I mostly work with Python 3.x. You can replace the pip3 part in the below examples with pip if you’re working with pip for Python 2.x.
We’ll install the numpy library as an example here.
1 2 3 4 |
root@ubuntu:~# pip3 install <package name> For Example -- root@ubuntu:~# pip3 install numpy <img class="alignnone wp-image-29588 size-full" src="http://all-learning.com/wp-content/uploads/2020/01/python3-pip-installation2.png" alt="python3-pip-installation" width="1200" height="628" /> |
If you would like to know what packages are available, you can use the search functionality of the pip command.
1 2 |
root@ubuntu:~# pip3 search numpy <img class="alignnone wp-image-29589 size-full" src="http://all-learning.com/wp-content/uploads/2020/01/pip-search-examples.png" alt="pip-search-example" width="1214" height="628" /> |
How to find the list of installed Python packages? We’ll use the list option for the pip command.
1 2 |
root@ubuntu:~# pip3 list <img class="alignnone wp-image-29590 size-full" src="http://all-learning.com/wp-content/uploads/2020/01/pip-list-example2.png" alt="pip-list-example" width="1200" height="663" /> |
You can safely ignore the warning in the output because it’s just to let us know that the default output format will change in the future.
If you’d like to know more about a package that you’ve installed, just use the show command.
1 2 |
root@ubuntu:~# pip3 uninstall numpy <img class="alignnone wp-image-29591 size-full" src="http://all-learning.com/wp-content/uploads/2020/01/pip-show-example1.png" alt="pip-show-example" width="1200" height="628" /> |
And to uninstall a package, we simply use pip3 uninstall <package name> as below.
1 2 |
root@ubuntu:~# pip3 uninstall numpy <img class="alignnone wp-image-29592 size-full" src="http://all-learning.com/wp-content/uploads/2020/01/pip-show-example3.png" alt="pip-show-example" width="1200" height="628" /> |
Conclusion
I know, it was really easy to install pip in Linux so I took the liberty to explain how you can start with using the command right away. As you work with Python, you’ll find yourself working with the pip command very often for installing and uninstalling packages.
We hope you enjoyed this tutorial!