Python Mogo ImportError:无法导入名称连接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29690786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 04:53:27  来源:igfitidea点击:

Python Mogo ImportError: cannot import name Connection

pythonmongodb

提问by 888

Can't figure out why this is not working.

无法弄清楚为什么这不起作用。

mogo==0.2.4

mogo==0.2.4

File "/Users/Sam/Envs/AdiosScraper/lib/python2.7/site-packages/mogo/connection.py", line 3, in <module>
    from pymongo import Connection as PyConnection
ImportError: cannot import name Connection

回答by thegreenogre

Mogo Connection

摩戈连线

from mogo import connect as PyConnection

pymongo.Connectionis deprecated use MongoClientinstead. In terms of use they are very similar.

pymongo.Connection已弃用MongoClient。在使用方面,它们非常相似。

回答by NoobEditor

i had same problem and too many files had the import, so, i couldn't risk changing the import- (didn't knew exactly where all it is mentioned).

我遇到了同样的问题,并且导入了太多文件,因此,我不能冒险更改import- (不知道所有提到的确切位置)。

I just downgraded pymongo:

我刚刚降级pymongo

sudo pip install pymongo==2.7.2

and it worked!

它奏效了!

回答by u4608304

Under PyMongo 3.2, you can connect to MongoDB like this:

在 PyMongo 3.2 下,你可以像这样连接到 MongoDB:

from pymongo import MongoClient
c = MongoClient()

mongo_client – Tools for connecting to MongoDB

mongo_client – 连接到 MongoDB 的工具

回答by serv-inc

In addition to https://stackoverflow.com/a/34766754/1587329, here's the API message(deprecated at 2.6.3, removed at 3.0):

除了https://stackoverflow.com/a/34766754/1587329 之外,这里是API 消息(在 2.6.3 弃用,在 3.0 删除):

Warning: DEPRECATED:Connectionis deprecated. Please use MongoClientinstead.

警告:已弃用:Connection已弃用。请MongoClient改用。