VianneyMI / monggregate

Library to make MongoDB aggregation framework and pipelines easy to use in python.
https://vianneymi.github.io/monggregate/
MIT License
22 stars 3 forks source link

error when importing monggregate #77

Closed OlivierLegrand closed 1 year ago

OlivierLegrand commented 1 year ago

In order to run the tutorial, I copy-pasted the code into a file named monggregate_tuto.py. When running this file in vscode, I get the following error:

File "(local directory)/monggregate/monggregate_tuto.py", line 3, in from monggregate import Pipeline, S File "(local directory)/monggregate/monggregate/init.py", line 3, in from monggregate.expressions import Expression File "(local directory)/monggregate/monggregate/expressions.py", line 10, in from monggregate.base import BaseModel, pyd File "(local directory)/monggregate/monggregate/base.py", line 15, in import pydantic.v1 as pyd

ImportError: dlopen((local directory)/monggregate/venv/lib/python3.11/site-packages/pydantic/init.cpython-311-darwin.so, 0x0002): tried: '(local directory)/monggregate/venv/lib/python3.11/site-packages/pydantic/init.cpython-311-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/(local directory)/monggregate/venv/lib/python3.11/site-packages/pydantic/init.cpython-311-darwin.so' (no such file), '(local directory)/monggregate/venv/lib/python3.11/site-packages/pydantic/init.cpython-311-darwin.so' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64'))

So it seems that the cause of the error is the pydantic.v1 import.

System info

macOS 13.6 python 3.11.5

suggestion

in the base.py file, the import is done within a try-catch statement:

try:
    import pydantic.v1 as pyd
except ModuleNotFoundError:
    import pydantic as pyd

so it tries to import pydantic.v1 instead of importing pydantic. Simply importing pydantic would (probably) work.