'On Apple M1, grpc/Google-Api Import Error:
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
Solution 1:[1]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Rahul |