ImportError: No module named objectid

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

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


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'm on Python3 (in 2017) and found that the following works:

from pymongo import MongoClient
from bson import ObjectId