[Fixed]-ImportError: No module named objectid

54👍

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
👤Vlad

3👍

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.

2👍

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

👤David

1👍

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

from pymongo import MongoClient
from bson import ObjectId

0👍

for me installing pymongo solved my issue:

pip3 install pymongo

source: https://kb.objectrocket.com/mongo-db/how-to-install-pymongo-and-connect-to-mongodb-in-python-363

👤john

Leave a comment