ImportError: No module named objectid

戏子无情 提交于 2019-11-27 15:06:21

I've ran into something similar, for me the problem was this line:

from pymongo.objectid import ObjectId

The call seems to work in versions of PyMongo < 2.2

In pymongo 2.2 the call to import objectid is:

from bson.objectid import ObjectId

Looks like they're already aware (see this pull request), but no one's created a pull request against the develop branch yet. You could try fixing that and submit a new pull request.

I tried to install bson with pip directly. Uninstall, and install pymongo instead and the error didnt reappear.

I'm on Python3 (in 2017) and found that the following works:

from pymongo import MongoClient
from bson import ObjectId
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!