How to Install pymongo in Python

v4.16.0 General Purpose Python >=3.9

PyMongo - the Official MongoDB Python driver

Install pip install pymongo

What is pymongo?

PyMongo - the Official MongoDB Python driver

The PyMongo distribution contains tools for interacting with MongoDB database from Python. The package is an implementation of the BSON format for Python. The package is a native Python driver for MongoDB, offering both synchronous and asynchronous APIs. The package is a gridfs implementation on top of .

PyMongo supports MongoDB 4.0, 4.2, 4.4, 5.0, 6.0, 7.0, and 8.0. PyMongo follows semantic versioning for its releases.

Documentation is available at mongodb.com.

Quick Start

Minimal example to get started with pymongo:

from pymongo import MongoClient

client = MongoClient("mongodb://localhost:27017/")
db = client["mydb"]
col = db["users"]

col.insert_one({"name": "Alice", "age": 30})
for doc in col.find():
    print(doc)

Installation

pip (standard)

pip install pymongo

Virtual environment (recommended)

python -m venv venv
source venv/bin/activate   # Windows: venv\Scripts\activate
pip install pymongo

pip3

pip3 install pymongo

conda

conda install -c conda-forge pymongo

Poetry

poetry add pymongo

Dependencies

Installing pymongo will also install these packages:

Verify the Installation

After installing, confirm the package is available:

python -c "import pymongo; print(pymongo.__version__)"

If this prints a version number, installation succeeded. If you see a ModuleNotFoundError, see the errors section below.

Installation Errors

Common errors when installing pymongo with pip.

ModuleNotFoundError: No module named 'pymongo'

Cause: The package is not installed in the current Python environment.

Fix: Run pip install pymongo. If using a virtual environment, ensure it is activated first.

ModuleNotFoundError: No module named 'pymongo' (installed but still failing)

Cause: pip installed the package into a different Python than the one running your script.

Fix: Use python -m pip install pymongo to install into the interpreter you are running.

ImportError: cannot import name 'X' from 'pymongo'

Cause: The function or class does not exist in the installed version.

Fix: Check the version with pip show pymongo and upgrade with pip install --upgrade pymongo.

pip: command not found

Cause: pip is not in PATH or Python was not added to PATH during installation.

Fix: Try python -m pip install pymongo. On macOS/Linux try pip3.

PermissionError: [Errno 13] Permission denied

Cause: No write access to the system Python package directory.

Fix: Use a virtual environment, or add --user: pip install --user pymongo

SSL: CERTIFICATE_VERIFY_FAILED

Cause: pip cannot verify PyPI's SSL certificate — common behind corporate proxies.

Fix: Try: pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org pymongo

Runtime Errors

Common errors when using pymongo after installation.

pymongo.errors.ServerSelectionTimeoutError

Cause: Cannot connect to MongoDB within the timeout period.

Fix: Ensure MongoDB is running (mongod). Default port is 27017.

pymongo.errors.DuplicateKeyError

Cause: Inserting a document violates a unique index constraint.

Fix: Use update_one(..., upsert=True) instead of insert_one to update if it exists.

Recent Releases

VersionReleased
4.16.0 latest 2026-01-07
4.16.0.dev0 2025-12-11
4.15.5 2025-12-02
4.15.4 2025-11-11
4.15.3 2025-10-07

Full release history on PyPI →

Manage pymongo

Upgrade to latest version

pip install --upgrade pymongo

Install a specific version

pip install pymongo==4.16.0

Uninstall

pip uninstall pymongo

Check what is installed

pip show pymongo

Last updated: 2026-04-11 • Data from PyPI