解决Python版本导致grpcio-tools-1.48.2安装失败问题

因为工作需要使用python开发grpc客户端,在mac电脑上通以下命令安装python的grpc依赖库总是不成功

pip3 install --no-cache-dir  --force-reinstall -Iv grpcio==1.48.2 grpcio-tools==1.48.2

clang -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -DHAVE_PTHREAD=1 -I. -Igrpc_root -Igrpc_root/include -Ithird_party/protobuf/src -I/Library/Frameworks/Python.framework/Versions/3.11/include/python3.11 -c third_party/protobuf/src/google/protobuf/util/time_util.cc -o build/temp.macosx-10.10-universal2-cpython-311/third_party/protobuf/src/google/protobuf/util/time_util.o -std=c++14 -fno-wrapv -frtti
  third_party/protobuf/src/google/protobuf/util/internal/protostream_objectwriter.cc:380:21: warning: comparison of integers of different signs: 'int' and 'std::vector<google::protobuf::util::converter::ProtoStreamObjectWriter::AnyWriter::Event>::size_type' (aka 'unsigned long') [-Wsign-compare]
    for (int i = 0; i < uninterpreted_events_.size(); ++i) {
                    ~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1 warning generated.
  clang -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -DHAVE_PTHREAD=1 -I. -Igrpc_root -Igrpc_root/include -Ithird_party/protobuf/src -I/Library/Frameworks/Python.framework/Versions/3.11/include/python3.11 -c third_party/protobuf/src/google/protobuf/util/type_resolver_util.cc -o build/temp.macosx-10.10-universal2-cpython-311/third_party/protobuf/src/google/protobuf/util/type_resolver_util.o -std=c++14 -fno-wrapv -frtti
  error: command '/usr/bin/clang' failed with exit code 1
  error: subprocess-exited-with-error

  × Building wheel for grpcio-tools (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> See above for output.

  note: This error originates from a subprocess, and is likely not a problem with pip.
  full command: /Library/Frameworks/Python.framework/Versions/3.11/bin/python3.11 /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py build_wheel /var/folders/ww/0rqb_9h96wz5t4n4wws3bkv40000gn/T/tmpzmc5aqew
  cwd: /private/var/folders/ww/0rqb_9h96wz5t4n4wws3bkv40000gn/T/pip-install-klp2us5i/grpcio-tools_d9c3a230080c45098badecabfb5d066d
  Building wheel for grpcio-tools (pyproject.toml) ... error
  ERROR: Failed building wheel for grpcio-tools
Failed to build grpcio grpcio-tools
ERROR: Could not build wheels for grpcio, grpcio-tools, which is required to install pyproject.toml-based projects

以为是pip源的问题,后来尝试下载whl文件本地安装, 但是提示

# pip3 install grpcio-1.48.2-cp310-cp310-macosx_10_10_x86_64.whl
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
ERROR: grpcio-1.48.2-cp310-cp310-macosx_10_10_x86_64.whl is not a supported wheel on this platform.

由此想到本地安装的是python311, 而whl下载的都是cp310,cp39 (项目组使用的protobuf是3.19.4,对应grepio版本最高时1.48.2版本,所有最高只能支持到cp310), 

于是通过 % python3 -m pip debug –verbose 命令查看支持的版本,果然都是cp311

至此定位,就是版本不匹配。 果断换成python310后,问题解决

% pip3 install grpcio==1.48.2 grpcio-tools==1.48.2
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting grpcio==1.48.2
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d8/86/e474e8e6979a7919bfec5906c7d76816904cc78f9b12f0d1abfee618b50e/grpcio-1.48.2-cp310-cp310-macosx_10_10_x86_64.whl (4.2 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.2/4.2 MB 15.6 MB/s eta 0:00:00
Collecting grpcio-tools==1.48.2
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d1/1e/7700466b6f85ade8f3bcb8975d5fe309a7f06ef5a49c00fa28f58e0edfdf/grpcio_tools-1.48.2-cp310-cp310-macosx_10_10_x86_64.whl (2.1 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 11.1 MB/s eta 0:00:00
Collecting six>=1.5.2 (from grpcio==1.48.2)
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d9/5a/e7c31adbe875f2abbb91bd84cf2dc52d792b5a01506781dbcf25c91daf11/six-1.16.0-py2.py3-none-any.whl (11 kB)
Requirement already satisfied: protobuf<4.0dev,>=3.12.0 in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from grpcio-tools==1.48.2) (3.19.4)
Requirement already satisfied: setuptools in /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages (from grpcio-tools==1.48.2) (69.1.1)
Installing collected packages: six, grpcio, grpcio-tools
Successfully installed grpcio-1.48.2 grpcio-tools-1.48.2 six-1.16.0

作者:悠等生2018

物联沃分享整理
物联沃-IOTWORD物联网 » 解决Python版本导致grpcio-tools-1.48.2安装失败问题

发表回复