After the new release of pymongo 4.9, I get this ImportError when using motor:
../***_mongo/src/***_mongo/async_context.py:4: in <module>
from motor.motor_asyncio import AsyncIOMotorClient, AsyncIOMotorDatabase
/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/motor/motor_asyncio.py:16: in <module>
from . import core, motor_gridfs
/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/motor/core.py:30: in <module>
from pymongo.cursor import _QUERY_OPTIONS, Cursor, RawBatchCursor
E ImportError: cannot import name '_QUERY_OPTIONS' from 'pymongo.cursor' (/opt/hostedtoolcache/Python/3.12.6/x64/lib/python3.12/site-packages/pymongo/cursor.py)
Simply try running the code:
from motor.motor_asyncio import AsyncIOMotorClient, AsyncIOMotorDatabase
print(AsyncIOMotorClient)
print(AsyncIOMotorDatabase)
The current motor release is completely broken due to this.
I tried to use the latest release of motor (3.5.1)
2
Answers
Until motor gets updated to account for the breaking changes in pymongo 4.9, pin pymongo to 4.8.0
For those experiencing this issue, please refer to the Jira ticket tracking it. We are currently investigating.
https://jira.mongodb.org/browse/PYTHON-4771
Current fix is either: