13

每次我尝试在项目中安装pip带有 GRPCIO 的包作为依赖项时,.direnv由于我的架构是 arm64,我都会遇到构建失败。在等待 GRPCIO 工作人员发布更新时,我该如何解决这个问题?

  Using cached grpcio-1.34.0.tar.gz (21.0 MB)
    ERROR: Command errored out with exit status 1:
     command: /Users/yoav/Library/Caches/pypoetry/virtualenvs/orca-g6p4a6cZ-py3.8/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/jj/r3j0p91s2qgdpcpf5ptqr9qm0000gn/T/pip-install-n05vw0u0/grpcio_103d947f24954cde8b8a019b4c9f88fe/setup.py'"'"'; __file__='"'"'/private/var/folders/jj/r3j0p91s2qgdpcpf5ptqr9qm0000gn/T/pip-install-n05vw0u0/grpcio_103d947f24954cde8b8a019b4c9f88fe/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/jj/r3j0p91s2qgdpcpf5ptqr9qm0000gn/T/pip-pip-egg-info-z41yqiw6
         cwd: /private/var/folders/jj/r3j0p91s2qgdpcpf5ptqr9qm0000gn/T/pip-install-n05vw0u0/grpcio_103d947f24954cde8b8a019b4c9f88fe/
    Complete output (10 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/jj/r3j0p91s2qgdpcpf5ptqr9qm0000gn/T/pip-install-n05vw0u0/grpcio_103d947f24954cde8b8a019b4c9f88fe/setup.py", line 359, in <module>
        if mac_target and (pkg_resources.parse_version(mac_target) <
      File "/Users/yoav/Library/Caches/pypoetry/virtualenvs/orca-g6p4a6cZ-py3.8/lib/python3.8/site-packages/pkg_resources/__init__.py", line 113, in parse_version
        return packaging.version.Version(v)
      File "/Users/yoav/Library/Caches/pypoetry/virtualenvs/orca-g6p4a6cZ-py3.8/lib/python3.8/site-packages/pkg_resources/_vendor/packaging/version.py", line 275, in __init__
        match = self._regex.search(version)
    TypeError: expected string or bytes-like object
    ASM Builds for BoringSSL currently not supported on: macosx-11-arm64
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
4

4 回答 4

18

这似乎运作良好,在终端中执行以下操作

export GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1
export GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1

然后安装您想要安装的任何软件包,在我的情况下,我试图安装 firebase admin,我必须运行以下命令

pip install firebase-admin

或者如果您只想安装 grpcio,只需运行以下命令

pip install grpcio

我发现这个线程有助于详细了解这个问题 https://github.com/grpc/grpc/issues/25082

于 2021-06-25T23:08:13.453 回答
10

我从https://github.com/grpc/grpc/issues/25082找到了一个可行的解决方案,其中包含更多细节并删除了某些不必要的步骤。请注意,截至本文发布日期,这仅适用于 python 版本 3.9。

首先,安装pyenvpyenv-virtualenv.

brew install pyenv pyenv-virtualenv

请注意,您可能需要使用 shell 评估变量,因为简单的添加eval "$(pyenv init -)"似乎不适用于 Apple M1 计算机。相反,运行以下

pyenv init - >> .zshrc
pyenv virtualenv-init - >> .zshrc

然后转到您的python项目目录并创建一个.envrc并注册它direnv

echo 'layout pyenv 3.9.1' > .envrc
direnv allow

接下来安装你的requirements.txtvia

GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1 GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1 pip install -r requirements.txt
Collecting google-cloud-pubsub
  Using cached google_cloud_pubsub-2.3.0-py2.py3-none-any.whl (210 kB)
Collecting proto-plus>=1.7.1
  Using cached proto_plus-1.17.0-py3-none-any.whl (42 kB)
Collecting grpc-google-iam-v1<0.13dev,>=0.12.3
  Using cached grpc-google-iam-v1-0.12.3.tar.gz (13 kB)
Collecting libcst>=0.3.10
  Using cached libcst-0.3.17-py3-none-any.whl (507 kB)
Collecting google-api-core[grpc]<2.0.0dev,>=1.22.2
  Using cached google_api_core-1.26.1-py2.py3-none-any.whl (92 kB)
Collecting protobuf>=3.12.0
  Using cached protobuf-3.15.6-py2.py3-none-any.whl (173 kB)
Collecting grpcio<2.0.0dev,>=1.0.0
  Using cached grpcio-1.36.1.tar.gz (21.5 MB)
Collecting googleapis-common-protos[grpc]<2.0.0dev,>=1.5.2
  Using cached googleapis_common_protos-1.53.0-py2.py3-none-any.whl (198 kB)
Collecting typing-inspect>=0.4.0
  Using cached typing_inspect-0.6.0-py3-none-any.whl (8.1 kB)
Processing /Users/rkmacmini/Library/Caches/pip/wheels/b7/a5/c4/504d913c2a55bb09c607541578ec5f844d1ff33467abe93ba5/PyYAML-5.4.1-cp39-cp39-macosx_11_0_arm64.whl
Collecting typing-extensions>=3.7.4.2
  Using cached typing_extensions-3.7.4.3-py3-none-any.whl (22 kB)
Collecting six>=1.13.0
  Using cached six-1.15.0-py2.py3-none-any.whl (10 kB)
Collecting google-auth<2.0dev,>=1.21.1
  Using cached google_auth-1.27.1-py2.py3-none-any.whl (136 kB)
Collecting pytz
  Using cached pytz-2021.1-py2.py3-none-any.whl (510 kB)
Requirement already satisfied: setuptools>=40.3.0 in ./.direnv/python-3.9.1/lib/python3.9/site-packages (from google-api-core[grpc]<2.0.0dev,>=1.22.2->google-cloud-pubsub->-r requirements.txt (line 1)) (49.2.1)
Collecting packaging>=14.3
  Using cached packaging-20.9-py2.py3-none-any.whl (40 kB)
Collecting requests<3.0.0dev,>=2.18.0
  Using cached requests-2.25.1-py2.py3-none-any.whl (61 kB)
Collecting mypy-extensions>=0.3.0
  Using cached mypy_extensions-0.4.3-py2.py3-none-any.whl (4.5 kB)
Collecting pyasn1-modules>=0.2.1
  Using cached pyasn1_modules-0.2.8-py2.py3-none-any.whl (155 kB)
Collecting cachetools<5.0,>=2.0.0
  Using cached cachetools-4.2.1-py3-none-any.whl (12 kB)
Collecting rsa<5,>=3.1.4; python_version >= "3.6"
  Using cached rsa-4.7.2-py3-none-any.whl (34 kB)
Collecting pyparsing>=2.0.2
  Using cached pyparsing-2.4.7-py2.py3-none-any.whl (67 kB)
Collecting idna<3,>=2.5
  Using cached idna-2.10-py2.py3-none-any.whl (58 kB)
Collecting urllib3<1.27,>=1.21.1
  Downloading urllib3-1.26.4-py2.py3-none-any.whl (153 kB)
     |████████████████████████████████| 153 kB 1.1 MB/s
Collecting certifi>=2017.4.17
  Using cached certifi-2020.12.5-py2.py3-none-any.whl (147 kB)
Collecting chardet<5,>=3.0.2
  Using cached chardet-4.0.0-py2.py3-none-any.whl (178 kB)
Collecting pyasn1<0.5.0,>=0.4.6
  Using cached pyasn1-0.4.8-py2.py3-none-any.whl (77 kB)
Using legacy 'setup.py install' for grpc-google-iam-v1, since package 'wheel' is not installed.
Using legacy 'setup.py install' for grpcio, since package 'wheel' is not installed.
Installing collected packages: six, protobuf, proto-plus, grpcio, googleapis-common-protos, grpc-google-iam-v1, mypy-extensions, typing-extensions, typing-inspect, pyyaml, libcst, pyasn1, pyasn1-modules, cachetools, rsa, google-auth, pytz, pyparsing, packaging, idna, urllib3, certifi, chardet, requests, google-api-core, google-cloud-pubsub
    Running setup.py install for grpcio ... done
    Running setup.py install for grpc-google-iam-v1 ... done
Successfully installed cachetools-4.2.1 certifi-2020.12.5 chardet-4.0.0 google-api-core-1.26.1 google-auth-1.27.1 google-cloud-pubsub-2.3.0 googleapis-common-protos-1.53.0 grpc-google-iam-v1-0.12.3 grpcio-1.36.1 idna-2.10 libcst-0.3.17 mypy-extensions-0.4.3 packaging-20.9 proto-plus-1.17.0 protobuf-3.15.6 pyasn1-0.4.8 pyasn1-modules-0.2.8 pyparsing-2.4.7 pytz-2021.1 pyyaml-5.4.1 requests-2.25.1 rsa-4.7.2 six-1.15.0 typing-extensions-3.7.4.3 typing-inspect-0.6.0 urllib3-1.26.4

注意:一些参考资料说您需要将 CFLAGS 等指向 brew 安装的 openssl 位置,但这对我来说似乎没有必要。如果您有问题,您可以尝试通过启用 CFLAGS 的命令

CFLAGS="-I /opt/homebrew/opt/openssl/include" LDFLAGS="-L /opt/homebrew/opt/openssl/lib" GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1 GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1 pip install -r requirements.txt
于 2021-03-15T15:14:48.047 回答
3

CFLAGS="-I /opt/homebrew/opt/openssl/include" LDFLAGS="-L /opt/homebrew/opt/openssl/lib" GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1 GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1 pip install -r requirements.txt 这对我有用我的 mac book pro M1 bigsur。感谢您的解决方案

于 2021-07-01T06:54:41.990 回答
1

有一个更简单、更可靠的选择:

pip uninstall grpcio
conda install grpcio
于 2022-02-23T17:48:19.753 回答