Ubuntu – How to install modules of python in Ubuntu

18.04pythonsoftware installation

I have python3 installed in Ubuntu 18.04 and I want to use different modules of python. Can anyone tell me how to install them?

Best Answer

The preferred way to install Python packages in Ubuntu is to install them from the default Ubuntu repositories with apt.

For Python 3.x search for the Python packages in the terminal with the command:

apt search python3-<package>

Replace <package> by the name of the package that you are searching for, e.g. python3-ipython.

For Python 2.x search for the Python packages in the terminal with the command:

apt search python-<package>

Replace <package> by the name of the package that you are searching for, e.g. python-ipython.

If you can't find a Python package that you want to install with apt search, you can install it from PyPI, the official third-party software repository for Python, with pip (for Python 2.x) or pip3 (for Python 3.x). pip integrates with virtualenv, doesn't do partial installs, can save package state for replaying, can install from non-egg sources, and can install from version control repositories.

Open the terminal and type:

for Python 3.x (python3 is installed by default in Ubuntu 18.04.)

sudo apt install python3-pip

for Python 2.x

sudo apt install python-pip  

After a Python package has been installed by python3 -m pip install <package-name> or python -m pip install <package-name>, you can run the following command to check if it is installed:

pip freeze | grep package-name
Related Question