grpc: grpcio fails to install on Apple Silicon
What version of gRPC and what language are you using?
grpcio-1.34.0
What operating system (Linux, Windows,…) and version?
macOS big Sur 11.0.1, running on M1 Apple Silicon
What runtime / compiler are you using (e.g. python version or version of gcc)
Python 3.8.7 (default, Dec 30 2020, 02:09:32)
[Clang 12.0.0 (clang-1200.0.32.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
$ clang --version
Apple clang version 12.0.0 (clang-1200.0.32.27)
Target: arm64-apple-darwin20.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
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.
pip install grpcio==1.34.0
What did you expect to see?
That grpcio will be successfully installed
What did you see instead?
Collecting 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.
Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).
See TROUBLESHOOTING.md for how to diagnose problems better.
Anything else we should know about your project / environment?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 58
- Comments: 82 (10 by maintainers)
Links to this issue
Commits related to this issue
- Add files via upload { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "<a href=\"https://colab.research.google.com/github/jeffheaton/t81_558_deep_learning/blo... — committed to hossain-sanowar/tensorflow_metal_M1 by hossain-sanowar 3 years ago
- fix: install grpcio on Apple M1 & python version notation 1. fix to install grpcio on Apple M1 platform read the link https://github.com/grpc/grpc/issues/25082 Some environment variables need to be s... — committed to lablup/backend.ai by studioego 2 years ago
- add instructions for Apple Silicon - set two environment variables - change Python 3.8 to 3.9 See here: https://github.com/grpc/grpc/issues/25082#issuecomment-778392661 — committed to dippa-1/gym-pybullet-drones by dippa-1 2 years ago
I managed to get the grpcio Python package installed on Python 3.9.1 installed via Pyenv on a M1 macOS:
Native arm64:
I had to set a few environment variables to get it to work:
to make the installation process use the libraries I’ve already got on the system, and then the following to point it at OpenSSL installed via Homebrew:
Setting the environment variables as recommended by @Tenzer works perfectly for me, too! Thank you! I used it to install stable_baselines3 on my Apple Silicon M1 🙂
I simply set the environment variables first:
Then installed the
grpcio
package with:At the time of writing this installs and works with
grpcio-1.35.0
@lidizheng @Tenzer Since it seems like this problem is not yet resolved I would offer help creating a PR, however I am completely new to this kind of stuff (pip install, setuptools etc.) and don’t really know where I would have to put the code. This is what I think would have to go somewhere according to your contributions:
Maybe in setup.py around line 82? Of course the required import statements are there already.
My Setup
Device: Apple M1 MacBook Pro running
macOS Big Sur 11.2
Python:Let me know if there is any more info that could be helpful!
I also added the wheel generated by pip if that is helpful to anyone. grpcio-1.35.0-cp39-cp39-macosx_11_0_arm64.whl.zip
you can use system python3 (/usr/bin/python3)
attention
arch -x86_64
should be used before the commandHello, since Google is doing nothing about this, I decided to set up a periodic GitHub Actions workflow to provide daily builds of Apple Silicon wheels for Mac. It will automatically cut a new release the day a new
grpcio
version is released on PyPI.In the releases page of this repo you can find and download the wheels for Python 3.8, 3.9, 3.10, 3.11. (Use at your own risk, these are not tested.) https://github.com/pietrodn/grpcio-mac-arm-build
Would it be fair to say that this issue is not resolved? Should there be another one opened, or this one perhaps? We’ve got OSS users that encounter this problem somewhat regularly
I just tried to install the library from the master branch with the fix included, but it still fails out of the box.
Is the version of BoringSSL and zlib referenced in this repository supposed to be working on ARM macOS? If not it might be better to try and detect when running on a ARM Mac (
platform.machine()
can do this) and set the equivalent of the following environment variables automatically:Does that sound reasonable? If so, I don’t mind trying to put a PR together to do that.
Running Python 3.8.8 within a miniforge conda (v4.10.3) environment: Setting the environment variables didn’t resolve the problem for me - each time
pip install grpcio
failed:conda install grpcio
directly worked@gnossen I and my team has experienced
gprcio
source build failures many times and discovered that depending on the development stack configurations the required build flags are vastly different laptop by laptop. Just installing XCode with command line tools and latest homebrew did not solve the problem and sometimes we could not figure out what installation/configuration triggers such difference.It would be nice if we have a concrete guide to how to set up the
grpcio
build environment on macOS and/or the pre-built binary wheel distribution for Apple Silicon.I tried doing many of the above, and unfortunately all failed for me. Ended up getting it to work by following the steps here (but for grpcio) https://stackoverflow.com/questions/65564673/how-do-i-import-pandas-on-apple-m1-chip. Posting in case it’s helpful to anyone in the future.
This did not work for me either for
grpcio==1.47.0
, but it does for1.44.0
@dgaedcke I don’t have a M1 machine. The answer is based on what I read.
Have you try to build your environment with emulated x86?
Then you should be able to use x86 Python, and x86
grpcio
binary wheel, no compilation needed.Still having this problem after having tried the above. Also, the listed solutions are pretty involved workarounds. Is someone working on a more permanent fix?
Here’s what worked on my setup.
My configuration:
/opt/homebrew
What worked was a combination of @matanby’s comment and some
CFLAGS
/LDFLAGS
options that worked in the past from my colleagues.I verified and both are needed: removing either makes the compilation fail. Other flags and compilation options weren’t useful.
With this combination of things,
grpcio
correctly compiles on Python 3.8, 3.9, and 3.10 (installed via pyenv).@hunt3r Same issue, M1 Monterey, Python 3.9.10
Fixed it
Inside virtualenv:
and then
pip install grpcio
It works
I was able to resolve this error via
Just simply export and install through pip package installer
I am getting this error today it worked last night. I have tried all the above solution and still seem to get the same thing:
MacBook Pro (13-inch, M1, 2020) Chip M1
1.52.0 has been released with proper universal2 artifacts which support both x86 macs and M1/2 macs.
I ran into this (again) today so I came back to check out the bug.
@gnossen can you provide guidance on when a fix will make it into a release so
pip
users will no longer encounter this?This worked for me (Python 3.9, Big Sur), native compiled, no need to add
arch -x86_64
before pip commandI got a successful build using @Tenzer 's solution, with addition of CFLAGS and LDFLAGS using
brew --prefix protobuf
,brew --prefix openssl
,brew --prefix zlib
, and setting theGRPC_PYTHON_BUILD_SYSTEM_*
environment variables, with arm64 homebrew and Python 3.9.1 built via pyenv’s latest master.I couldn’t easily get a build process working on my Monterey M1, but the binary worked.
Details:
Setting the two environment variables still left me with
when trying to
import grpc
.Maybe “If we export magic variables from the conda recipe, keep conda libraries installed and install Cython, then” would have worked, but I don’t understand this enough to do it confidently (keep what installed how?). I haven’t read the whole thread.
conda install -c conda-forge grpcio
gave meInstalling the binary wheel from the latest artifact at https://github.com/pietrodn/grpcio-mac-arm-build/actions by downloading it and
worked a treat. Thank you so much!! ❤️
If anyone still encounters compilation errors when trying to
pip install grpcio
on a M1 Mac, and none of the above suggestions work, try this:This solved the problem in my case.
Also, another piece of information that might be helpful in solving this: I was able to successfully install
grpcio
before I had installed xcode. Seems to me like there is a mismatch in the binary tools used for the compilation; the ones that come in/Library/Developer/CommandLineTools
work file, while those that come bundled with xcode do not.1.52.0 is Yanked
Folks, I’m still having the issue and I believe this should be open until:
Thank you so much for this. Worked like a charm in my Macbook Pro M1 with Big Sur (11.4)
Yes, someone please respond … I’ve already burned over 2 days on this error!!
I’ve tried Homebrew w Py3.8, Py3.9 and Conda-miniforge with both as well I’ve tried bash arm64, bash x86, zsh arm64
I’ve even tried the Panda’s example above but it didn’t solve the problem for me…
How do I install and run this library?? The failure stacktrace is below:
import google.cloud.ndb as ndb File “/opt/homebrew/Caskroom/miniforge/base/envs/env/lib/python3.8/site-packages/google/cloud/ndb/init.py”, line 28, in <module> from google.cloud.ndb.client import Client File “/opt/homebrew/Caskroom/miniforge/base/envs/env/lib/python3.8/site-packages/google/cloud/ndb/client.py”, line 18, in <module> import grpc File “/opt/homebrew/Caskroom/miniforge/base/envs/env/lib/python3.8/site-packages/grpc/init.py”, line 23, in <module> from grpc._cython import cygrpc as _cygrpc ImportError: dlopen(/opt/homebrew/Caskroom/miniforge/base/envs/env/lib/python3.8/site-packages/grpc/_cython/cygrpc.cpython-38-darwin.so, 2): Symbol not found: _CFRelease Referenced from: /opt/homebrew/Caskroom/miniforge/base/envs/env/lib/python3.8/site-packages/grpc/_cython/cygrpc.cpython-38-darwin.so Expected in: flat namespace in /opt/homebrew/Caskroom/miniforge/base/envs/env/lib/python3.8/site-packages/grpc/_cython/cygrpc.cpython-38-darwin.so
@lidizheng so we are still facing this issue with grpc 1.48.1 on macOS 12 on M1.
The installation via
pip install grpcio
works, but after successful installation the resulting shared object cannot be loaded:The wheel is not used during the installation, so the artefact is built on the local machine, but the results are busted.
If we export magic variables from the conda recipe, keep conda libraries installed and install Cython, then
pip install grpcio
produces a working artefact:With system libraries without conda provided libraries the installation fails.
We would really appreciate if you guys can manage to upload arm64 wheels and/or at least fix your installation process to produce working artefacts on M1 by default without dark conda recipe environment variable magic.
/cc @mm-ivanovig @marns93
It’s not quite a guide, but after lots of trial and error the invocation that worked for me was:
YMMV!
It works for me.
God bless you @Tenzer - it works now! I’ve wasted so much time googling the solution. Thank you so much. ❤️
1.51.3 has now been released with universal2 artifacts. I’ll leave this issue open for a couple more days in case there are further issues.
@techdragon ✅ Done! https://github.com/pietrodn/grpcio-mac-arm-build/releases
I lost a full day on this. Here’s how I managed to make it work.
If you install python while running in arm mode it won’t work. I’ve tried many Python versions with conda, pipenv, venv, Poetry.
You need to compile Python in x86_64 mode.
I use asdf but it should work with pyenv and similar tools.
I hope this helps.
none of the solutions above worked for me. It ended up being setuptools version. grpcio installation would fail with setuptools==60+ after changiing the env setuptools version to 57.5.0, grpcio installs fine.
Resolved install python 3.9.8 or superior 😄 🚀
Yeah I had to do it with Conda, a pyenv environment did not work for me. Feels weird but I got past the issue for now.
Also works with python 3.8.11 in a conda environment if followed the above steps!
It was a long long error about the wheel. I resolved it by removing this flag: GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1
For some reason it wanted to use another ssl library.
Thanks @Tenzer and @achimnol! This worked for me as well.
Note if the following issue occurs after those recommendations:
Edit version.py line 275 on your system to:
@levrik Yes, to confirm, 1.52.0 includes prebuilt universal2 artifacts which work on both x86-64 and arm64 macs. The release candidate is already uploaded and the official release is scheduled for later this week.
Of course the issue should be open, it is not fixed. I don’t understand the trend on GitHub to close issues before a fix has been created, it is not like the issue goes away just by marking the issue closed:( Now it is almost 2 years since the issue was created and nobody cares enough about this to actually do the work needed to fix it. It is really frustrating that an important package like this can not be installed by pip without problems.
On my Mac m1 12.6 python 3.10.6 I was not able to install 1.50.0 I simply gave up trying get it compiled 😦 and installed 1.46.3 with the following env vars set: GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1 GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1 GRPC_BUILD_WITH_BORING_SSL_ASM= GRPC_PYTHON_BUILD_SYSTEM_CARES=True GRPC_PYTHON_USE_PREBUILT_GRPC_CORE= GRPC_PYTHON_BUILD_WITH_CYTHON=True GRPC_PYTHON_LDFLAGS= -framework CoreFoundation
Not sure if the env vars matter though
I had a similar issue with installing
grpcio=1.47.0
but I usedpipenv
andPipfile.lock
What helped me - do uninstall pipenv previously installed with pip and install it again but with homebrew:brew install pipenv
Then,pipenv
could installgrpcio
without any problemsJust for reference…
If you need to install
grpcio
throughpoetry
you need to force the installation of the source package. And to make the compilation work you need to set up the following envvars beforepoetry install
:or directly with
poetry install
:The content of
pyproject.toml
will need the following session to force the use of the source package in Apple M1 (arm64
) architechture:I was also not able to fix this problem. The installation would be successful but importing grpc would fail (shown below)
However, installing from conda would be just fine, so I checked their instructions. I was missing some build flags via imports. The following export statements worked for me, and hope they would be helpful for you as well. Taken from here.
This works for me (M1 Air)
And change the default CC to clang inorder to fix
gcc: error: unrecognized command-line option '-stdlib=libc++'
errorgrpcio 1.38.1 is used to have the issue but it seems that it’s finally fixed in 1.39.0 \m/
@yoav-orca We currently doesn’t have ARM64 machines to produce binary wheels, but we are working on a plan.
Back to the build, the failure is not caused by the ASM optimization. Can you check the result of
sysconfig.get_config_var('MACOSX_DEPLOYMENT_TARGET')
on your Mac? It seems returning a number or some sort, which supposed to be a string (or bytes) of targeted macOS version.EDIT: if none presented, you could try to set it to your macOS version, e.g. Big Sur is
11.0
.