Skip to content Skip to sidebar Skip to footer

Pymongo==3.0.3: Importerror: No Module Named Connection

I just upgraded to pymongo==3.0.3 via pip install --upgrade pymongo, and I'm flooded with ImportError: In [2]: pymongo.version Out[2]: '3.0.3' In [3]: from pymongo import Connecti

Solution 1:

According to Pymongo 3.0 changelog -

MongoClient changes

MongoClient is now the one and only client class for a standalone server, mongos, or replica set. It includes the functionality that had been split into MongoReplicaSetClient: it can connect to a replica set, discover all its members, and monitor the set for stepdowns, elections, and reconfigs. MongoClient now also supports the full ReadPreference API.

The obsolete classes MasterSlaveConnection, Connection, and ReplicaSetConnection are removed.

As you can see Connection class has been removed from pymonge 3.0 , try using MongoClient instead. Information about mongoclient can be found here

Solution 2:

Probably you can support both versions in your code by doing something like this.

try:
    from pymongo.connection import Connection
except ImportError as e:
    from pymongo import MongoClient as Connection

Solution 3:

Since Connection class is deprecated from pymongo(3.0.0). Install a older version of pymongo(2.9) to make it temporarily work. It can be done with pip using:

pip install  pymongo==2.9

Post a Comment for "Pymongo==3.0.3: Importerror: No Module Named Connection"