Pip install on Mac OS gets error: command '/usr/bin/clang' failed with exit code 1
Asked Answered
M

12

43

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:

Mullane answered 17/11, 2020 at 18:52 Comment(0)
M
25

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
Machellemachete answered 26/5, 2022 at 12:5 Comment(5)
This was also on M1 processor? Do you know why it works? it's a compatibility fixed in newer pip? May you link the docs? in my case it worked without upgrading setup tools.Taler
@ChristianH, I was on Intel processor. No, I did not know the reason behind it. I just tried those commands.Machellemachete
Thanks @Arkhan, it works perfectly on Mac M1 processor!Moulton
it didn't work for me... mac os monterey intel ...Ungenerous
I had the same problem using python 3.9 installed by pyenv and did these upgrades and worked, thanks. oh I use mac m2 proVazquez
M
13

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.

Matrilocal answered 17/11, 2020 at 19:3 Comment(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?Mullane
GCP is like a toxic gf. Always trying to make your life hardImprescriptible
L
5

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
Luane answered 3/5, 2022 at 17:6 Comment(0)
B
4

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
Butternut answered 28/5, 2021 at 19:29 Comment(0)
R
3

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

Runnerup answered 28/6, 2022 at 12:32 Comment(0)
B
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).

Bobodioulasso answered 1/1, 2021 at 16:5 Comment(2)
Thanks for this suggestion, but unfortunately this didn't work for me - same problem as before. Trying the answer above this one now!Durative
It will install the x86_64 version of grpcio and get some compatibility problem in the future.Algesia
R
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 )

Redfield answered 17/5, 2022 at 23:53 Comment(0)
K
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?

Kammerer answered 27/6, 2022 at 16:1 Comment(0)
B
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
Berylberyle answered 28/9, 2022 at 19:7 Comment(0)
L
0

I had the same problem, I followed these steps and it worked for me:

1- update pip:

python -m pip install --upgrade pip

2- Install OpenSSL:

brew install openssl re2

source : here

Land answered 5/10, 2023 at 14:59 Comment(0)
K
0

run pip install --upgrade setuptools can be solved :)

Kohima answered 5/12, 2023 at 18:4 Comment(0)
L
-1

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)

Lutyens answered 29/6, 2023 at 1:56 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.