Find Guide on Installing Pip on Ubuntu

install pip ubuntu

Pip is a package manager that facilitates the installation and management of Python software packages, for instance, those contained in the Python Package Index (PyPI).

In this article, I am going to show you how to install and use pip on Ubuntu 18.04.

Install pip for Python3 on Ubuntu

By default, Ubuntu 18.04 comes with Python3 in its installation. To install pip3 for Python3 follow the following steps

Update the system

# sudo apt-get update

Install pip for python3

# sudo apt-get install python3-pip

This command installs pip together with all the dependencies necessary for building python modules.

Sample Output

The following NEW packages will be installed:
libpython3-dev libpython3.4 libpython3.4-dev python3-chardet
python3-colorama python3-dev python3-distlib python3-html5lib python3-pip
python3-requests python3-setuptools python3-six python3-urllib3
python3-wheel python3.4-dev
0 upgraded, 15 newly installed, 0 to remove and 26 not upgraded.
Need to get 20.2 MB of archives.
After this operation, 38.7 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y

Checking the version of pip3

To check the version of pip3 run the command below

# pip3 –version

OR

# pip3 -V

Output

pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)

Install pip for Python2 on Ubuntu

Python2 is not installed by default on Ubuntu 18.04. If you wish to install Python2 and pip for Python 2 run the following commands

Update the system

# sudo apt-get update

Install pip for python2

# sudo apt-get install python-pip

Checking the version of pip

To verify the installation of pip, run

# pip –version

OR

# pip -V

Output

# pip 10.0.1 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)

Using pip in package management

Now that we have seen how to install various versions of pip in different python environments, it’s time to see how we can use it to install, upgrade and uninstall packages.

Installing a package with pip

When installing python modules, it’s recommended that you do so in virtual environments. a virtual environment creates an isolated environment for several python projects. This allows you to install a specific module per project without worrying about the module affecting other Python projects.

To install a package with pip

# pip3 install package_name

For instance

# pip install numpy

Output

Collecting numpy
Downloading https://files.pythonhosted.org/packages/40/c5/f1ed15dd931d6667b40f 1ab1c2fe1f26805fc2b6c3e25e45664f838de9d0/numpy-1.15.2-cp27-cp27mu-manylinux1_x86 _64.whl (13.8MB)
100% |████████████████████████████████| 13.8MB 3.2MB/s
Installing collected packages: numpy
Successfully installed numpy-1.15.2
You are using pip version 10.0.1, however version 18.1 is available.
You should consider upgrading via the ‘pip install –upgrade pip’ command.

To install a specific version of a package

If you wish to specify installation of a specific package run,

# pip3 install package_name==version no.

For example

# pip3 install numpy=1.15

Output

Collecting numpy==1.15
Downloading https://files.pythonhosted.org/packages/29/b9/479ccb55cc7dcff3d4fc7c8c26d4887846875e7d4f04483a36f335bed712/numpy-1.15.0-cp35-cp35m-manylinux1_x86_64.whl (13.8MB)
100% |████████████████████████████████| 13.8MB 101kB/s
Installing collected packages: numpy
Successfully installed numpy-1.15.0
You are using pip version 10.0.1, however version 18.1 is available.
You should consider upgrading via the ‘pip install –upgrade pip’ command.

To upgrade a package with pip

To upgrade a package to its latest version using pip run

# pip3 install –upgrade package_name

For example, we have seen from the output above that we are running pip version 10.0.1. To upgrade to the latest version which is 18.1, run

# pip3 install –upgrade pip

Output

Collecting pip
Downloading https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl (1.3MB)
100% |████████████████████████████████| 1.3MB 7.5MB/s
Installing collected packages: pip
Found existing installation: pip 10.0.1
Uninstalling pip-10.0.1:
Successfully uninstalled pip-10.0.1
Successfully installed pip-18.1

To uninstall a package with pip

To uninstall a package with pip run

# pip3 uninstall package_name

For example

# pip3 uninstall numpy

Output

Uninstalling numpy-1.15.2:
Would remove:
/usr/local/bin/f2py
/usr/local/lib/python2.7/dist-packages/numpy-1.15.2.dist-info/*
/usr/local/lib/python2.7/dist-packages/numpy/*
Proceed (y/n)? y

Viewing more options with pip

To view more pip options on the usage of pip run

# pip3 –help

install and use pip on Ubuntu

In this guide, we have seen how to install and use pip on Ubuntu to install, upgrade and uninstall packages. For more options on pip usage, visit this documentation.

Read Also:

Source

Leave a Reply

Your email address will not be published. Required fields are marked *

WP2Social Auto Publish Powered By : XYZScripts.com