grpc: Unable to install grpcio 1.51.0 for Python on Mac OS Apple M1

What version of gRPC and what language are you using?

grpcio==1.51.0 grpcio-tools=1.51.0

What operating system (Linux, Windows,…) and version?

Mac OS Ventura (Apple M1) 13.0.1

What runtime / compiler are you using (e.g. python version or version of gcc)

Python 3.11.0 / 3.10.8 / 3.9.15

What did you do?

Please provide either 1) A unit test for reproducing the bug or 2) Specific steps for us to follow to reproduce the bug. If there’s not enough information to debug the problem, gRPC team may close the issue at their discretion. You’re welcome to re-open the issue once you have a reproduction.

I wanted to upgrade a Poetry project depending on grpcio, and I’m facing a setuptools errors while trying to install the new wheel.

I’ve tried to install the project manually through pip with this command line:

$ pip install --upgrade grpcio grpcio-tools

And I was still unable to update my project dependency.

What did you expect to see?

A successful installation.

What did you see instead?

$ pip install --upgrade grpcio grpcio-tools
Collecting grpcio
  Using cached grpcio-1.51.0.tar.gz (22.1 MB)
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'done'
Collecting grpcio-tools
  Downloading grpcio-tools-1.51.0.tar.gz (2.3 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.3/2.3 MB 24.5 MB/s eta 0:00:00
  Preparing metadata (setup.py): started
  Preparing metadata (setup.py): finished with status 'done'
Requirement already satisfied: protobuf<5.0dev,>=4.21.6 in ./.venv/lib/python3.9/site-packages (from grpcio-tools) (4.21.9)
Requirement already satisfied: setuptools in ./.venv/lib/python3.9/site-packages (from grpcio-tools) (65.6.0)
Building wheels for collected packages: grpcio, grpcio-tools
  Building wheel for grpcio (setup.py): started
  Building wheel for grpcio (setup.py): finished with status 'error'
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [2106 lines of output]
      Boringssl currently does not support macOS arm64, so we'll try to use the system installation of 'openssl' to build by default, make sure you have 'openssl' installed in this case
      Found cython-generated files...
      running bdist_wheel
      running build
      running build_py
      running build_project_metadata
      ... Truncated mkdir and file copy ...
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -D_WIN32_WINNT=1536 -DGRPC_XDS_USER_AGENT_NAME_SUFFIX=\"Python\" -DGRPC_XDS_USER_AGENT_VERSION_SUFFIX=\"1.51.0\" -DOPENSSL_NO_ASM=1 -DGPR_BACKWARDS_COMPATIBILITY_MODE=1 -DHAVE_CONFIG_H=1 -DGRPC_ENABLE_FORK_SUPPORT=1 "-DPyMODINIT_FUNC=extern \"C\" __attribute__((visibility (\"default\"))) PyObject*" -DGRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK=1 -Isrc/python/grpcio -Iinclude -I. -Ithird_party/abseil-cpp -Ithird_party/address_sorting/include -Ithird_party/cares/cares/include -Ithird_party/cares -Ithird_party/cares/cares -Ithird_party/cares/config_darwin -Ithird_party/re2 -I/usr/include/openssl -Ithird_party/upb -Isrc/core/ext/upb-generated -Isrc/core/ext/upbdefs-generated -Ithird_party/xxhash -Ithird_party/zlib -I/path/to/.venv/include -I/opt/homebrew/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c src/core/ext/filters/census/grpc_context.cc -o python_build/temp.macosx-12-arm64-cpython-39/src/core/ext/filters/census/grpc_context.o -std=c++14 -stdlib=libc++ -fvisibility=hidden -fno-wrapv -fno-exceptions -DHAVE_UNISTD_H -pthread
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -D_WIN32_WINNT=1536 -DGRPC_XDS_USER_AGENT_NAME_SUFFIX=\"Python\" -DGRPC_XDS_USER_AGENT_VERSION_SUFFIX=\"1.51.0\" -DOPENSSL_NO_ASM=1 -DGPR_BACKWARDS_COMPATIBILITY_MODE=1 -DHAVE_CONFIG_H=1 -DGRPC_ENABLE_FORK_SUPPORT=1 "-DPyMODINIT_FUNC=extern \"C\" __attribute__((visibility (\"default\"))) PyObject*" -DGRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK=1 -Isrc/python/grpcio -Iinclude -I. -Ithird_party/abseil-cpp -Ithird_party/address_sorting/include -Ithird_party/cares/cares/include -Ithird_party/cares -Ithird_party/cares/cares -Ithird_party/cares/config_darwin -Ithird_party/re2 -I/usr/include/openssl -Ithird_party/upb -Isrc/core/ext/upb-generated -Isrc/core/ext/upbdefs-generated -Ithird_party/xxhash -Ithird_party/zlib -I/path/to/.venv/include -I/opt/homebrew/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc -o python_build/temp.macosx-12-arm64-cpython-39/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.o -std=c++14 -stdlib=libc++ -fvisibility=hidden -fno-wrapv -fno-exceptions -DHAVE_UNISTD_H -pthread
      ... Truncated clang invokations ...
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -D_WIN32_WINNT=1536 -DGRPC_XDS_USER_AGENT_NAME_SUFFIX=\"Python\" -DGRPC_XDS_USER_AGENT_VERSION_SUFFIX=\"1.51.0\" -DOPENSSL_NO_ASM=1 -DGPR_BACKWARDS_COMPATIBILITY_MODE=1 -DHAVE_CONFIG_H=1 -DGRPC_ENABLE_FORK_SUPPORT=1 "-DPyMODINIT_FUNC=extern \"C\" __attribute__((visibility (\"default\"))) PyObject*" -DGRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK=1 -Isrc/python/grpcio -Iinclude -I. -Ithird_party/abseil-cpp -Ithird_party/address_sorting/include -Ithird_party/cares/cares/include -Ithird_party/cares -Ithird_party/cares/cares -Ithird_party/cares/config_darwin -Ithird_party/re2 -I/usr/include/openssl -Ithird_party/upb -Isrc/core/ext/upb-generated -Isrc/core/ext/upbdefs-generated -Ithird_party/xxhash -Ithird_party/zlib -I/path/to/.venv/include -I/opt/homebrew/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c third_party/upb/upb/array.c -o python_build/temp.macosx-12-arm64-cpython-39/third_party/upb/upb/array.o -stdlib=libc++ -fvisibility=hidden -fno-wrapv -fno-exceptions -DHAVE_UNISTD_H -pthread
      creating None
      creating None/var
      creating None/var/folders
      creating None/var/folders/9g
      creating None/var/folders/9g/r8cmr5nd44s4z_c_2379ntym0000gn
      creating None/var/folders/9g/r8cmr5nd44s4z_c_2379ntym0000gn/T
      creating None/var/folders/9g/r8cmr5nd44s4z_c_2379ntym0000gn/T/tmp6oq83wvk
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.sdk -I/path/to/.venv/include -I/opt/homebrew/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c /var/folders/9g/r8cmr5nd44s4z_c_2379ntym0000gn/T/tmp6oq83wvk/a.c -o None/var/folders/9g/r8cmr5nd44s4z_c_2379ntym0000gn/T/tmp6oq83wvk/a.o
      Traceback (most recent call last):
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/unixccompiler.py", line 186, in _compile
          self.spawn(compiler_so + cc_args + [src, '-o', obj] + extra_postargs)
        File "/private/var/folders/9g/r8cmr5nd44s4z_c_2379ntym0000gn/T/pip-install-og0qtd4c/grpcio_c8eb1bc5f558437e82b7ca1b2ea4139b/src/python/grpcio/_spawn_patch.py", line 54, in _commandfile_spawn
          _classic_spawn(self, command)
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/ccompiler.py", line 1007, in spawn
          spawn(cmd, dry_run=self.dry_run, **kwargs)
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/spawn.py", line 70, in spawn
          raise DistutilsExecError(
      distutils.errors.DistutilsExecError: command '/usr/bin/clang' failed with exit code 1
      
      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "/private/var/folders/9g/r8cmr5nd44s4z_c_2379ntym0000gn/T/pip-install-og0qtd4c/grpcio_c8eb1bc5f558437e82b7ca1b2ea4139b/src/python/grpcio/commands.py", line 280, in build_extensions
          build_ext.build_ext.build_extensions(self)
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py", line 468, in build_extensions
          self._build_extensions_serial()
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py", line 494, in _build_extensions_serial
          self.build_extension(ext)
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/command/build_ext.py", line 246, in build_extension
          _build_ext.build_extension(self, ext)
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py", line 549, in build_extension
          objects = self.compiler.compile(
        File "/private/var/folders/9g/r8cmr5nd44s4z_c_2379ntym0000gn/T/pip-install-og0qtd4c/grpcio_c8eb1bc5f558437e82b7ca1b2ea4139b/src/python/grpcio/_parallel_compile_patch.py", line 58, in _parallel_compile
          multiprocessing.pool.ThreadPool(BUILD_EXT_COMPILER_JOBS).map(
        File "/opt/homebrew/Cellar/python@3.9/3.9.15/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py", line 364, in map
          return self._map_async(func, iterable, mapstar, chunksize).get()
        File "/opt/homebrew/Cellar/python@3.9/3.9.15/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py", line 771, in get
          raise self._value
        File "/opt/homebrew/Cellar/python@3.9/3.9.15/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py", line 125, in worker
          result = (True, func(*args, **kwds))
        File "/opt/homebrew/Cellar/python@3.9/3.9.15/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py", line 48, in mapstar
          return list(map(*args))
        File "/private/var/folders/9g/r8cmr5nd44s4z_c_2379ntym0000gn/T/pip-install-og0qtd4c/grpcio_c8eb1bc5f558437e82b7ca1b2ea4139b/src/python/grpcio/_parallel_compile_patch.py", line 54, in _compile_single_file
          self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
        File "/private/var/folders/9g/r8cmr5nd44s4z_c_2379ntym0000gn/T/pip-install-og0qtd4c/grpcio_c8eb1bc5f558437e82b7ca1b2ea4139b/src/python/grpcio/commands.py", line 263, in new_compile
          return old_compile(obj, src, ext, cc_args, extra_postargs,
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/unixccompiler.py", line 188, in _compile
          raise CompileError(msg)
      distutils.errors.CompileError: command '/usr/bin/clang' failed with exit code 1
      
      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/private/var/folders/9g/r8cmr5nd44s4z_c_2379ntym0000gn/T/pip-install-og0qtd4c/grpcio_c8eb1bc5f558437e82b7ca1b2ea4139b/setup.py", line 546, in <module>
          setuptools.setup(
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/__init__.py", line 87, in setup
          return distutils.core.setup(**attrs)
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 185, in setup
          return run_commands(dist)
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
          dist.run_commands()
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
          self.run_command(cmd)
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/dist.py", line 1217, in run_command
          super().run_command(command)
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/path/to/.venv/lib/python3.9/site-packages/wheel/bdist_wheel.py", line 299, in run
          self.run_command('build')
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
          self.distribution.run_command(command)
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/dist.py", line 1217, in run_command
          super().run_command(command)
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/command/build.py", line 132, in run
          self.run_command(cmd_name)
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
          self.distribution.run_command(command)
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/dist.py", line 1217, in run_command
          super().run_command(command)
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
          cmd_obj.run()
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/command/build_ext.py", line 84, in run
          _build_ext.run(self)
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py", line 346, in run
          self.build_extensions()
        File "/private/var/folders/9g/r8cmr5nd44s4z_c_2379ntym0000gn/T/pip-install-og0qtd4c/grpcio_c8eb1bc5f558437e82b7ca1b2ea4139b/src/python/grpcio/commands.py", line 284, in build_extensions
          raise CommandError(
      commands.CommandError: Failed `build_ext` step:
      Traceback (most recent call last):
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/unixccompiler.py", line 186, in _compile
          self.spawn(compiler_so + cc_args + [src, '-o', obj] + extra_postargs)
        File "/private/var/folders/9g/r8cmr5nd44s4z_c_2379ntym0000gn/T/pip-install-og0qtd4c/grpcio_c8eb1bc5f558437e82b7ca1b2ea4139b/src/python/grpcio/_spawn_patch.py", line 54, in _commandfile_spawn
          _classic_spawn(self, command)
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/ccompiler.py", line 1007, in spawn
          spawn(cmd, dry_run=self.dry_run, **kwargs)
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/spawn.py", line 70, in spawn
          raise DistutilsExecError(
      distutils.errors.DistutilsExecError: command '/usr/bin/clang' failed with exit code 1
      
      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "/private/var/folders/9g/r8cmr5nd44s4z_c_2379ntym0000gn/T/pip-install-og0qtd4c/grpcio_c8eb1bc5f558437e82b7ca1b2ea4139b/src/python/grpcio/commands.py", line 280, in build_extensions
          build_ext.build_ext.build_extensions(self)
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py", line 468, in build_extensions
          self._build_extensions_serial()
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py", line 494, in _build_extensions_serial
          self.build_extension(ext)
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/command/build_ext.py", line 246, in build_extension
          _build_ext.build_extension(self, ext)
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/command/build_ext.py", line 549, in build_extension
          objects = self.compiler.compile(
        File "/private/var/folders/9g/r8cmr5nd44s4z_c_2379ntym0000gn/T/pip-install-og0qtd4c/grpcio_c8eb1bc5f558437e82b7ca1b2ea4139b/src/python/grpcio/_parallel_compile_patch.py", line 58, in _parallel_compile
          multiprocessing.pool.ThreadPool(BUILD_EXT_COMPILER_JOBS).map(
        File "/opt/homebrew/Cellar/python@3.9/3.9.15/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py", line 364, in map
          return self._map_async(func, iterable, mapstar, chunksize).get()
        File "/opt/homebrew/Cellar/python@3.9/3.9.15/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py", line 771, in get
          raise self._value
        File "/opt/homebrew/Cellar/python@3.9/3.9.15/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py", line 125, in worker
          result = (True, func(*args, **kwds))
        File "/opt/homebrew/Cellar/python@3.9/3.9.15/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py", line 48, in mapstar
          return list(map(*args))
        File "/private/var/folders/9g/r8cmr5nd44s4z_c_2379ntym0000gn/T/pip-install-og0qtd4c/grpcio_c8eb1bc5f558437e82b7ca1b2ea4139b/src/python/grpcio/_parallel_compile_patch.py", line 54, in _compile_single_file
          self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
        File "/private/var/folders/9g/r8cmr5nd44s4z_c_2379ntym0000gn/T/pip-install-og0qtd4c/grpcio_c8eb1bc5f558437e82b7ca1b2ea4139b/src/python/grpcio/commands.py", line 263, in new_compile
          return old_compile(obj, src, ext, cc_args, extra_postargs,
        File "/path/to/.venv/lib/python3.9/site-packages/setuptools/_distutils/unixccompiler.py", line 188, in _compile
          raise CompileError(msg)
      distutils.errors.CompileError: command '/usr/bin/clang' failed with exit code 1
      
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for grpcio
  Running setup.py clean for grpcio
  Building wheel for grpcio-tools (setup.py): started
  Building wheel for grpcio-tools (setup.py): finished with status 'done'
  Created wheel for grpcio-tools: filename=grpcio_tools-1.51.0-cp39-cp39-macosx_12_0_arm64.whl size=1889028 sha256=01a33f1fdde7f11a87ad82211aa73c9f79cc9c85ba735aec144d0a857b81d351
  Stored in directory: /Users/rigma/Library/Caches/pip/wheels/17/1d/7a/1d007fdff1149d47af524dbb20479c5ee32a81636b302a6fbd
Successfully built grpcio-tools
Failed to build grpcio

... Same errors with legacy pip installation ...

× Encountered error while trying to install package.
╰─> grpcio

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

I’ve got the same output for Python 3.10 and 3.11.

Anything else we should know about your project / environment?

My project is setup thanks to Poetry with the following pyproject.toml subset:

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "example-project"
version = "0.0.0"
readme = "README.md"
packages = [
    { include = "app" },
]

[tool.poetry.dependencies]
python = "^3.9"
dependency-injector = { version = "4.40.0", extras = ["pydantic"] }
fastapi = "0.87.0"
google-cloud-storage = "2.6.0"
orjson = "3.8.2"
pydantic = { version = "1.10.2", extras = ["email"] }
typing-extensions = "4.4.0"

[tool.poetry.group.dev.dependencies]
alembic = "1.8.1"
black = "*"
pyproject-parser = "0.7.0"
pytest = "7.2.0"
pytest-asyncio = "0.20.2"
pytest-cov = "4.0.0"
uvicorn = "0.19.0"

[tool.pytest.ini_options]
addopts = "--cov app --cov-report term --cov-report xml:cov.xml --disable-warnings --strict-markers"
asyncio_mode = "strict"
testpaths = ["tests"]
markers = []
filterwarnings = []

[tool.coverage.run]
branch = true
source = ["app"]
omit = ["app/__main__.py"]

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 9
  • Comments: 21 (12 by maintainers)

Most upvoted comments

This seemed to fix it for me:

brew install openssl
export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"
export GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1
export GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1

poetry install

The code changes for this are complete and universal2 artifacts will be published with the next release.

@gnossen yes, I’ve just solved the problem for my dependency forest by pinning grpcio<1.51.0

1.51.0 has been yanked. For those affected, please consider testing against our release candidates in the future by adding a test job that installs with pip install --pre grpcio

In that case, I’m going to go ahead and yank 1.51.0 and revert https://github.com/grpc/grpc/pull/31096. Thanks for the reports, everyone!

CC @amchii