This brief tutorial shows students and new users how to install and use Python pip on Ubuntu 20.04 | 18.04.
Pip is python tool for installing Python packages. It is used to search, download and install package from Python package index as well as other indexes.
Python comes in either python 2 or Python 3. With Ubuntu 20.04, Python 3 is the default. For systems that depend on Python 2, the steps below also show you how to install it.
PiP isn’t installed by default on Ubuntu. But installing it is pretty easy and straightforward. The steps below will guide you through the installation and management of Python packages via PiP.
For student or new user looking for a Linux system to start learning on, the easiest place to start is Ubuntu Linux OS…. It’s a great Linux operating system for beginners and folks looking for easier Linux distribution to use.
Ubuntu is an open source Linux operating systems that runs on desktops, laptops, server and other devices.
When using Ubuntu, you will find that Linux isn’t so different than Windows and other operating systems in so many ways, especially when it comes to using the system to get work done.
Both Ubuntu and Windows systems allow you to be productive, easy to use, reliable and enable you to install and run thousands of programs from gaming to productivity suite software for individuals and businesses.
Install PiP for Python 3
If you’re running the latest Python version and you wish to use pip to manage packages, then use the steps below.
The commands below install PiP to be used with Python version 3.
sudo apt update sudo apt install python3-pip
When you run the commands above, all dependencies that are required to for PiP to function will be installed along side PiP.
To validate whether PiP is installed, simply run the commands below:
You should see similar line as below:
Output: pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8)
That’s how to get PiP installed for use with Python 3.
Install pip for Python 2
If you want Python 2 for legacy systems, then use the steps below to install it as well as pip for Python 2.
Again, PiP doesn’t come installed with Ubuntu, so you will have to run the commands below to install it.
sudo add-apt-repository universe sudo apt update sudo apt install python-pip
Now that Python 2 is installed, you can now install pip using get-pip.py script. After enabling the repository and install it above, simply download the script and run it to install Python globally.
curl https://bootstrap.pypa.io/get-pip.py --output get-pip.py sudo python2 get-pip.py
The script will also install pip, setuptools and wheel.
Installing Packages with PiP
Now that PiP is installed, you can begin installing Python packages using it.
If you don’t already how to use PiP, simply run its help command to display helpful command options and how to use them..
pip3 --help pip install --help
You should see helpful commands and how to use them as shown below
Usage: pip [options] Commands: install Install packages. download Download packages. uninstall Uninstall packages. freeze Output installed packages in requirements format. list List installed packages. show Show information about installed packages. check Verify installed packages have compatible
When working with Python projects, it’s always a good idea to create a virtual environment. Generally PiP package installer is used within Python virtual environments where each environment are isolated for specific projects.
After each project is done, it can be discarded easily.
For this post, you want to create a PiP virtual environment within your home folder or directory.
Simply run the command below to create a Python 3 virtual environment called confidential.
First install Python virtual environment module by running the commands below:
sudo apt install python3-venv
Then create a new environment called confidential
python3 -m venv ~/confidential
Simply activate the environment by running the commands below:
Within this specific environment, you can begin installing packages via PiP to use with Python 3.
For example, to install a Python package called python-openstackclient, simply run the commands below:
pip3 install python-openstackclient
That should install the python-openstackclient package to use with Python 3.
To upgrade packages via PiP, simply run the commands below:
pip3 install --upgrade python-openstackclient
To uninstall packages via PiP, simply run the commands below:
pip3 uninstall python-openstackclient
When you’re done with the Python project, simply run the deactivate command to return to your normal shell.
This post shows you how to install PiP on Ubuntu 18.04 | 16.04 to to install and manage Python packages or modules. If you find any error above, please use the comment form below to report it.
You may also like the post below: