Jan 10, 2019 This tutorial describes two ways of installing Python 3.7 on Ubuntu 18.04: By using the standard apt tool from the deadsnakes PPA, and by building from the source code. The same steps apply for Ubuntu 16.04 and any Ubuntu-based distribution, including Kubuntu, Linux Mint and Elementary OS.
Pip (Pip Install Packages) is a command line utility tool used to install and manage software packages written in Python. Like apt and yum, it is a package management system and mainly used to download and install packages from the Python Package Index (PyPI). Pip does not get installed by default in Ubuntu 18.04. However, the installation of Python Pip using the apt package manager is very simple.
This tutorial will show you how to install python Pip in your Ubuntu 18.04 system using apt. Thereafter, we will also check a few essential usages of Python Pip.
Table of Contents
- 4 Essential Pip Commands
Prerequisite
- You can open a SSH session in your Ubuntu 18.04 system using
root
or asudo
enabled user.
Pip for Python 3
Ubuntu 18.04 ships with Python 3 and therefore you need to install pip3 specifically for python 3. To start with, update the package list in your system:
Next, execute the following command to install Pip for python 3 and all the dependencies needed for designing Python modules.
Finally, find the version of Pip to verify the installation:
![Ubuntu Ubuntu](http://ubuntuhandbook.org/wp-content/uploads/2017/07/python-versions-600x143.jpg)
Pip for Python 2
Although Python 3 is installed by default in Ubuntu 18.04, it is very much possible to have both Python 2 and Python 3 installed in your system. So if you want to manage packages for Python 2, you need to install pip for Python 2.
Start by updating the package list in your system.
Now install pip for Python 2 along with all other dependencies for building Python modules using following
apt
command:Remember, the above command will install Python 2 as well if you have not installed it previously.
Finally, find the version of Pip to verify the installation:
PIP Version
Essential Pip Commands
At this point, Pip should be installed in your system. Let us walk through a few useful pip commands to get you started with it.
Pip should be used within Python virtual environments which allows you to install and manage packages in a secure way for each Python projects separately. This ensures installing or deleting packages from one Python project does not affect another.
Although this tutorial will not cover about Python virtual environment or how to create it, you can use the following Pip commands either inside Python virtual environment or outside it.
1. List installed packages
To find all the installed Pip packages run the following command from the terminal:
2. Search package
To search packages from the Python Package Index, execute the following pip command from the terminal:
3. Install packages
To install the latest version of Python package using Pip, use the following command from the terminal.
It is also possible to install a specific version of Python package by specifying the version number with Pip command.
4. Install packages using requirements.txt
Sometimes you want to install multiple packages with the specific version number for your Python project. You can list the name of all the packages that need to be installed along with their version number in the requirements.txt file.
To use requirement file for installing packages, create and edit a file by the name requirements.txt and specify a list of packages along with their version number in it.
Now to install packages, run the
pip3 install
command by specifying requirements file using the -r switch:5. Upgrade package
To upgrade an installed package, use the
--upgrade
switch along with package name like the following command.6. Delete package
To remove an installed package, specify the package name to be deleted with the pip command:
If you are using Python 2 then replace pip3 with pip in the above pip commands.
Summary
In this tutorial, we have covered how to install Pip for Python 2 and Python 3 in an Ubuntu 18.04 system. Further, we have also covered a few basic usages of Pip to get you started with it. You can always invoke pip manual pages by using
pip3 --help
from terminal to find more options and usages of python Pip.