问题描述:
使用 pip 已经更新 grpcio 至最新版,调用时还是报错 如下图:
Traceback (most recent call last):
File "/Users/yu/anaconda3/envs/dify2/lib/python3.10/site-packages/flask/cli.py", line 245, in locate_app
__import__(module_name)
File "/Users/yu/Desktop/code/yuCode/pyCode/dify/api/app.py", line 8, in <module>
import grpc.experimental.gevent
File "/Users/yu/anaconda3/envs/dify2/lib/python3.10/site-packages/grpc/__init__.py", line 22, in <module>
from grpc import _compression
File "/Users/yu/anaconda3/envs/dify2/lib/python3.10/site-packages/grpc/_compression.py", line 20, in <module>
from grpc._cython import cygrpc
ImportError: dlopen(/Users/yu/anaconda3/envs/dify2/lib/python3.10/site-packages/grpc/_cython/cygrpc.cpython-310-darwin.so, 2): no suitable image found. Did find:
/Users/yu/anaconda3/envs/dify2/lib/python3.10/site-packages/grpc/_cython/cygrpc.cpython-310-darwin.so: mach-o, but wrong architecture
/Users/yu/anaconda3/envs/dify2/lib/python3.10/site-packages/grpc/_cython/cygrpc.cpython-
解决方案:
在 ~/.bash_profile 或者 ~/.zshrc 添加环境变量
export GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1
export GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1
export GRPC_PYTHON_LDFLAGS=" -framework CoreFoundation"
再次执行 成功运行
pip install grpcio --no-binary :all: