pymongo==3.0.3: ImportError: No module named connection
pymongo==3.0.3: ImportError: No module named connection
我刚刚通过 pip install --upgrade pymongo
升级到 pymongo==3.0.3
,我被 ImportError
:
淹没了
In [2]: pymongo.version
Out[2]: '3.0.3'
In [3]: from pymongo import Connection
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-3-dd44bc3249d3> in <module>()
----> 1 from pymongo import Connection
ImportError: cannot import name Connection
In [4]: from pymongo import connection
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-4-71c9e4ec1bcd> in <module>()
----> 1 from pymongo import connection
ImportError: cannot import name connection
In [5]: import pymongo.connection.Connection
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-282b89157c85> in <module>()
----> 1 import pymongo.connection.Connection
ImportError: No module named connection.Connection
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.
如您所见,Connection class 已从 pymonge 3.0 中删除,请尝试改用 MongoClient。关于mongoclient的信息可以参考here
也许您可以通过执行类似操作在您的代码中支持这两个版本。
try:
from pymongo.connection import Connection
except ImportError as e:
from pymongo import MongoClient as Connection
因为 Connection class 已从 pymongo(3.0.0) 中弃用。安装旧版本的 pymongo(2.9) 使其暂时可用。可以使用 pip 来完成:
pip install pymongo==2.9
我刚刚通过 pip install --upgrade pymongo
升级到 pymongo==3.0.3
,我被 ImportError
:
In [2]: pymongo.version
Out[2]: '3.0.3'
In [3]: from pymongo import Connection
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-3-dd44bc3249d3> in <module>()
----> 1 from pymongo import Connection
ImportError: cannot import name Connection
In [4]: from pymongo import connection
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-4-71c9e4ec1bcd> in <module>()
----> 1 from pymongo import connection
ImportError: cannot import name connection
In [5]: import pymongo.connection.Connection
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-282b89157c85> in <module>()
----> 1 import pymongo.connection.Connection
ImportError: No module named connection.Connection
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.
如您所见,Connection class 已从 pymonge 3.0 中删除,请尝试改用 MongoClient。关于mongoclient的信息可以参考here
也许您可以通过执行类似操作在您的代码中支持这两个版本。
try:
from pymongo.connection import Connection
except ImportError as e:
from pymongo import MongoClient as Connection
因为 Connection class 已从 pymongo(3.0.0) 中弃用。安装旧版本的 pymongo(2.9) 使其暂时可用。可以使用 pip 来完成:
pip install pymongo==2.9