前期准备gcc、Cython、python-devel等
centos下:
yum groups mark install "Development Tools"
yum install -y Cython
yum install -y python-devel
ubuntu下:
apt install -y install build-essential
apt install -y cython
apt install -y python-dev
源码安装python版本的grpc库:
1. clone源码(选择对应的版本),更新依赖库(时间比较长)
git clone https://github.com/grpc/grpc
cd grpc
git submodule update --init
2. 安装python依赖
pip install --upgrade pip
pip install -rrequirements.txt
GRPC_PYTHON_BUILD_WITH_CYTHON=1 pip install .
之后就可以去 examples/python/helloworld 启动两个终端分别启动 server和client 了
python -u greeter_server.py
python -u greeter_client.py
client返回 "Hello you"
测试中间遇到的问题:
1. 直接用python setup.py install安装时gcc提示错误,Cython提示错误。请用上述命令重新安装
gcc: error: src/python/grpcio/grpc/_cython/cygrpc.c: No such file or directory
gcc: fatal error: no input files
#error Extensions have been poisoned due to missing Cython-generated code.