skip to Main Content

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


  1. Until motor gets updated to account for the breaking changes in pymongo 4.9, pin pymongo to 4.8.0

    Login or Signup to reply.
  2. 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:

    • Upgrade to motor 3.6.0 which is compatible with (and requires) PyMongo >=4.9: pip install –upgrade ‘motor>=3.6’
    • If you’re using motor <3.6 and can’t upgrade, cap the pymongo version to <4.9: eg pip install –upgrade ‘motor==3.5.1’ ‘pymongo<4.9’
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search