问题描述
我刚刚通过pip install --upgrade pymongo
升级到了pymongo==3.0.3
,我被ImportError
充斥:
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 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
推荐答案
根据 Pymongo 3.0更新日志-
MongoClient现在是独立服务器,mongos或副本集的唯一且唯一的客户端类.它包括已拆分为MongoReplicaSetClient的功能:它可以连接到副本集,发现其所有成员,并监视该集的降级,选择和重新配置. MongoClient现在还支持完整的ReadPreference API.
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.
已删除的过时的类MasterSlaveConnection,Connection和ReplicaSetConnection.
The obsolete classes MasterSlaveConnection, Connection, and ReplicaSetConnection are removed.
如您所见,Connection类已从pymonge 3.0中删除,请尝试改用MongoClient.可以在此处找到有关mongoclient的信息. >
As you can see Connection class has been removed from pymonge 3.0 , try using MongoClient instead. Information about mongoclient can be found here
这篇关于pymongo == 3.0.3:ImportError:没有名为连接的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!