PyMongo is a python package that contains tools for connection to MongoDB. So if you have MongoDB installed for your application & you would like to connect to that from your python application, then you would be using PyMongo to make that connection. It’s the recommended way to work with MongoDB from python.

Recommended Read: Recommended guide to install POSTGRESQL from Source

Also Read: Install ROBO3T on Ubuntu (Install RoboMongo)

In simple words, PyMongo is a python driver for MongoDB & connects to MongoDB using python. In this tutorial, we will learn to install PyMongo on our Linux systems. But first, we will start with the pre-requisites.


Since we are going to make connections from python to MongoDB, obviously we would need to have both installed on our systems. Please refer to the following articles to install Python & MongoDB on your Linux systems.

Install python on Ubuntu

Install python on CentOS/RHEL

Install Python from source

Install MongoDB on Ubuntu & Ubuntu 16.04

Install MongoDB on CentOS/RHEL

Once we have these installed on our systems, we can process with the PyMongo installation.

Install PyMongo

We will be discussing three methods to install PyMongo on Linux systems,

1- Using PIP

2- Using easy_install

3- Using source package

Now let’s discuss all three methods in detail.

1- Using PIP

You should check if you have PIP installed on your systems. If it’s not installed, then you can tutorials to install it on CentOS/RHEL & on Ubuntu. Once that is installed, use the following commands to install PyMongo,

$ python -m pip install pymongo

To install a specific version, the command is,

$ python -m pip install pymongo==3.5.1

& if you need to upgrade the installed version, the command is,

$ python -m pip install –upgrade pymongo

2- Using easy_install

Easy_install is a python module that is part of the Python setuptools package, so if it is not installed on your system, install it using the following command on Ubuntu,

$ sudo apt-get install python-setuptools

Or you can also install it all systems that have pip installed with the following command,

$ pip install setuptools

Once the package has been installed, we can use easy_install for PyMongo installation,

$ python -m easy_install pymongo

To upgrade it, the command is,

$ $ python -m easy_install -U pymongo

Now let’s discuss the final method, i.e. install using Source packages.

3- Using source package

We need to first install some dependencies first, then we can install the PyMongo on our systems. For Ubuntu/Debian, execute the following command from the terminal,

$ sudo apt-get install build-essential python-dev

For Redhat/CentOS, use the following command,

# yum install gcc python-devel

Now we can download the PyMongo packages from the GitHub repository & install it on our systems,

$ git clone git:// pymongo

$ cd pymongo/

$ python install

That’s it, PyMongo is now installed on our systems. We can now use it to connect to MongoDB from Python. This also concludes our tutorial on the installation of PyMongo on Linux systems. Please do let us know about your questions, queries or suggestions, you can use the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.