On Apple M1, grpc/Google-Api Import Error:
Asked Answered
S

1

6

Situation:

I'm trying to set up my SQLAlchemy database and run it locally. I use the google api for its vision module, so I can analyze text off of pictures.

Currently I had to switch from an old 2013 macbook to a new 2020 macbook with the m1 chip. I try to run my local environment but receive the following error.

ERROR:

File "/Users/gabriel/Desktop/PROJECT_NAME/src/main.py", line 3, in <module>
    import actions
  File "/Users/gabriel/Desktop/PROJECT_NAME/src/actions.py", line 3, in <module>
    import utils
  File "/Users/gabriel/Desktop/PROJECT_NAME/src/utils.py", line 5, in <module>
    import google.cloud.vision_v1 as vision
  File "/Users/gabriel/.local/share/virtualenvs/PROJECT_NAME/lib/python3.10/site-packages/google/cloud/vision_v1/__init__.py", line 20, in <module>
    from .services.image_annotator import ImageAnnotatorClient as IacImageAnnotatorClient
  File "/Users/gabriel/.local/share/virtualenvs/PROJECT_NAME/lib/python3.10/site-packages/google/cloud/vision_v1/services/image_annotator/__init__.py", line 16, in <module>
    from .client import ImageAnnotatorClient
  File "/Users/gabriel/.local/share/virtualenvs/PROJECT_NAME/lib/python3.10/site-packages/google/cloud/vision_v1/services/image_annotator/client.py", line 25, in <module>
    from google.api_core import gapic_v1  # type: ignore
  File "/Users/gabriel/.local/share/virtualenvs/PROJECT_NAME/lib/python3.10/site-packages/google/api_core/gapic_v1/__init__.py", line 16, in <module>
    from google.api_core.gapic_v1 import config
  File "/Users/gabriel/.local/share/virtualenvs/PROJECT_NAME/lib/python3.10/site-packages/google/api_core/gapic_v1/config.py", line 23, in <module>
    import grpc
  File "/Users/gabriel/.local/share/virtualenvs/PROJECT_NAME/lib/python3.10/site-packages/grpc/__init__.py", line 22, in <module>
    from grpc import _compression
  File "/Users/gabriel/.local/share/virtualenvs/PROJECT_NAME/lib/python3.10/site-packages/grpc/_compression.py", line 15, in <module>
    from grpc._cython import cygrpc
ImportError: dlopen(/Users/gabriel/.local/share/virtualenvs/PROJECT_NAME/lib/python3.10/site-packages/grpc/_cython/cygrpc.cpython-310-darwin.so, 0x0002): tried: '/Users/gabriel/.local/share/virtualenvs/PROJECT_NAME/lib/python3.10/site-packages/grpc/_cython/cygrpc.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/lib/cygrpc.cpython-310-darwin.so' (no such file)

Hypothesis:

I believe it does have to do with trying to get the universal binary version in my dependencies, but at this point, I have no idea how link them correctly or if I even have the right package.

Specs:

  • OS: Mac OS Monterey 12.0.1 (21A559)

  • Computer: MacBook Pro (13-inch, M1, 2020)

  • IDE: VSCode

Dependencies:

  • Python: "3.10.0"

  • grpcio: "1.41.1"

  • sqlalchemy: "1.4.26"

Tried Solutions:

  • Ran without grpcio dependency, worked.

  • Originally ran database on two non-m1 chip macbooks, did not have this error.

  • Uninstalled and reinstalled grpcio without cache.

  • Deleted my local environment and recreated it

Subvert answered 31/10, 2021 at 16:59 Comment(1)
hi Gabriel have you checked here ? github.com/grpc/grpc/issues/25082Stonedeaf
S
7

Run the following commands from within your shell (or from within your virtual environment)

pip install --no-binary :all: grpcio --ignore-installed
pip install --no-binary :all: grpcio-tools --ignore-installed

You can find more info from this comment made here for the Github Issue

Stefansson answered 10/3, 2022 at 23:24 Comment(2)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Stanwinn
Update: The issue is fixed in grpcio 1.47.0 and newer.Bicameral

© 2022 - 2024 — McMap. All rights reserved.