33

I want to install google-cloud-pubsub via pip installation on Mac OS but I get an error: distutils.errors.CompileError: command '/usr/bin/clang' failed with exit code 1. The command I run: pip install google-cloud-pubsub==2.1.0.

Here the complete error message.

Any suggestion? Thank you!

More info:

$ python -V
Python 3.9.0

$ pip -V
pip 20.2.4 from /.../lib/python3.9/site-packages/pip (python 3.9)

$ sw_vers
ProductName:    macOS
ProductVersion: 11.0.1
BuildVersion:   20B29

I've seen other similar cases but them don't solve my issue. I tried:

Ismail
  • 1,068
  • 1
  • 6
  • 11
Fausto Fusaro
  • 506
  • 1
  • 4
  • 10

10 Answers10

20

I was using pyenv and facing the similar kind of issue. Then I did the following and it worked.

First, upgrade pip

pip3 install --upgrade pip

Then, update the setup tools:

python3 -m pip install --upgrade setuptools
ARKhan
  • 1,724
  • 22
  • 30
12

Try to add these env var before

GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=true GRPC_PYTHON_BUILD_SYSTEM_ZLIB=true pip install google-cloud-pubsub==2.1.0

If it does not work you can try with virtualenv:

pip install virtualenv
virtualenv my-test-env
source my-test-env/bin/activate
my-test-env/bin/pip install google-cloud-pubsub==2.1.0

Because is written on github:

Install this library in a virtualenv using pip. virtualenv is a tool to create isolated Python environments. The basic problem it addresses is one of dependencies and versions, and indirectly permissions.

With virtualenv, it's possible to install this library without needing system install permissions, and without clashing with the installed system dependencies.

Gabouchet
  • 181
  • 9
  • 2
    Thank you so much but, no luck! I get the same error. I tried to configure the GRPC_PYTHON_BUILD_SYSTEM_RE2 but it doesn't work as well. I'm only using a venv. Any further suggestion? – Fausto Fusaro Nov 18 '20 at 19:46
4

I ended up just using Python 3.8.13 instead, managed with pyenv and pyenv-virtualenv.

If you don't have pyenv:

brew install pyenv pyenv-virtualenv

add

export PATH="$HOME/.pyenv/bin:$PATH"
export PATH="$HOME/.pyenv/shims:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"

to your ~/.zshrc if it's not there, and source ~/.zshrc

pyenv install 3.8.13
pyenv global 3.8.13
pyenv virtualenv 3.8.13 venv
pyenv activate venv
pip install grcpio
Shao
  • 41
  • 1
3

I just had this same problem but I'm using homebrew to manage my Mac packages. My error result was the same as yours but within the error message it was:

plyvel/_plyvel.cpp:632:10: fatal error: 'leveldb/db.h' file not found
#include "leveldb/db.h"

This can be fixed using homebrew by just installing leveldb:

brew install leveldb

This allowed the plyvel dependency to be satisified. I then manually installed plyvel just to be safe:

pip3 install plyvel

And lastly because I'm trying to install the airflow libraries that include pubsub:

pip3 install apache-airflow-providers-google
2

Are you attempting to compile on a new M1 processor? I ran into trouble installing the latest grpcio (1.34.0) too, with the same error message as you.

Without messing with compile flags and libraries, I found the best solution for me (setting up a new Flask environment to talk to Google Cloud on a new Big Sur Mac) was the tip offered here:

https://osxdaily.com/2020/11/18/how-run-homebrew-x86-terminal-apple-silicon-mac/

  1. Duplicate your Terminal rename it to "Rosetta Terminal" or similar
  2. Get Info on the new app, and check the box for "Open using Rosetta"
  3. Do your work with this new terminal app instead

grpcio installed fine for me this way, and I don't anticipate any problems running my Web apps in this translated environment (until I presume this issue gets fixed in the source libraries).

  • 4
    Thanks for this suggestion, but unfortunately this didn't work for me - same problem as before. Trying the answer above this one now! – samjewell Apr 07 '21 at 19:59
  • It will install the x86_64 version of grpcio and get some compatibility problem in the future. – dogewang Oct 26 '21 at 12:02
1

I encountered a similarly-named clang issue when attempting to awsiotsdk on an M1 Mac with Python 3.8

Incase it's relevant to anyone reading this, the underlying issue was a dependency on awscrt. This particular library (on PyPi) did not contain Built Distributions for the combination of M1 ("xxx_universal2.whl") and Python 3.8.

The solution was to use pyenv with pipenv (a favourite pattern of mine) to force this project to use a supported combination (in our case: Python 3.9 with M1 )

JoshEM1994
  • 11
  • 3
1

if you are using Mac M1 chip, just do the below thing it worked for me.

export GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=1
export GRPC_PYTHON_BUILD_SYSTEM_ZLIB=1

Thanks for the below answer. How can I install GRPCIO on an Apple M1 Silicon laptop?

1

Working solution in my case (Mac M1 Monterey OS):

brew install openssl re2
LDFLAGS="-L$(/opt/homebrew/bin/brew --prefix openssl)/lib -L$(/opt/homebrew/bin/brew --prefix re2)/lib" CPPFLAGS="-I$(/opt/homebrew/bin/brew --prefix openssl)/include -I$(/opt/homebrew/bin/brew --prefix re2)/include" GRPC_BUILD_WITH_BORING_SSL_ASM="" GRPC_PYTHON_BUILD_SYSTEM_RE2=true GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=true GRPC_PYTHON_BUILD_SYSTEM_ZLIB=true pip install grpcio

Credits to https://github.com/grpc/grpc/issues/24677#issuecomment-862413344

ImustAdmit
  • 388
  • 4
  • 14
0

I started having that issue. Following this comment, with pyenv, I uninstalled my python 3.9.12 and reinstalled it again.

I am having an M1 and macOS 12.6, btw.

Deactivate your current virtualenv first, then:

pyenv uninstall 3.9.12
pyenv install 3.9.12
pyenv local 3.9.12 # to set your local python version to the newly installed python
poetry shell
pip install grpcio # or poetry install grpcio
Amirsalar
  • 648
  • 9
  • 18
0

For anyone looking for a fix, using MAC_OS : Ventura 13.4.1:

Error:

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools),
missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

Fix:

xcode-select --install
# Reopen teminal after installation
# Activate virualenv if you have
pip install greenlet

You can run above command even if you already have any old versions. Above command will redownload macos command line tools. (If you already have it)

Smit Patel
  • 1,682
  • 18
  • 23