Install Python on Ubuntu 18.04

Ubuntu 18.04 comes with python 3 installation out of the box as default interpreter. In the minimal installation of Ubuntu this does not come pre-installed so now we are going to install Python on Ubuntu 18.04.

Prerequisites

Before you start installing Python on Ubuntu 18.04. You must have nonroot user account on your server with sudo privileges.

Before You Begin

Before we begin please check whether Python is installed or not on your system by typing

python --version

If the output shows Python version then you already have Python installed or if it outputs command not found then Python is not installed. However, you can also upgrade or downgrade version of Python.

Install Python 3 on Ubuntu

Update package manager index by typing following command

sudo apt update

The following command will provide minimal installation of Python. now to install Python 3 enter following command

sudo apt install python3-minimal

Confirm the installation and check the version of Python by entering the following command.

python3 -V

The output should be:

Output
    Python 3.6.6

Install Python 2 On Ubuntu

Before you install Python on ubuntu 18.04, update package manager index by typing following command.

sudo apt update

Following command will provide minimal installation of Python. now to install Python 2 enter following command.

sudo apt install pytho3-minimal

Confirm installation and check version of Python by entering follwing command.

python --version

Output should be:

Output:
    Python 2.7.15rc1

Install Python Modules

Ubutnu repository already have a lot of Python modules. To Search Python modules enter following command

sudo apt search MODULE_NAME

To install searched Python module enter following command

sudo apt install MODULE_NAME

Best way to install and manage python packages

PIP stands for Python Package Index which most popular tool for installation and management of Python packages. You cand check more information about this tool on following link : How to install PIP on Ubuntu 18.04

Conclusion

Here we have learnt how to install Python on Ubuntu 18.04. If You have any queries regarding this then please comment below.

Install PIP on Ubuntu 18.04

PIP stands for Python Package Index (PyPI) used for installation and management of software packages in Python. PIP makes it very easier to install packages in Python. Now you are going to install PIP on Ubuntu 18.04 and you will also learn some basic commands in PIP.

Prerequisites

Before you start to install PIP on Ubuntu 18.04. You must have non root user account on your server with sudo privileges.

Before You Begin

By default Python 3 is installed in Ubuntu 18.04 but if you have made any changes then you can check version of python by entering following

    python --version
    Output:
        Python 3.6

1. Install PIP for Python 3

Before start installing PIP on Ubuntu, you should update package index by entering following.

sudo apt update

Now to install PIP on Ubuntu enter following command

sudo apt install python3-pip

To confirm installation and check version of PIP enter following command

pip3 --version

Output should be :

Output:
    pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)

If output comes as above then you have successfully installed PIP on Ubuntu .

NOTE – version number of PIP may change with time.

2. Install PIP For Python 2

Update the package manager index by entering following command

sudo apt update

After updating package manager index to install PIP for Python 2 enter following in terminal

sudo apt install python-pip

Check version and confirm installation by entering following

pip --version

Output should be :

Output
    pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)

3. Basic usage of PIP for python 3

To list all the commands in PIP enter following

pip3 --help

Get information of specific command enter following

pip3 install --help

To search package with PIP enter following

pip3 search PACKAGE_NAME

Install package with PIP enter following in terminal

pip3 install PACKAGE_NAME

To install package from requirements file

pip3 install -r requirements.txt

Upgrade package with PIP

pip3 install --upgrade PACKAGE_NAME

Uninstall package with PIP

pip3 uninstall PACKAGE_NAME

4. Basic usage of PIP for python 2

To list all the commands in PIP enter following

pip --help

Get information of specific command enter following

pip install --help

To search package with PIP enter following

pip search PACKAGE_NAME

Install package with PIP enter following in terminal

pip install PACKAGE_NAME

To install package from requirements file

pip install -r requirements.txt

Upgrade package with PIP

pip install --upgrade PACKAGE_NAME

Uninstall package with PIP

pip uninstall PACKAGE_NAME

Conclusion

Here you have learnt how to install PIP on Ubuntu 18.04 for python 3 and python 2. If you have any queries regarding this please don’t forget to comment below.