Fausto Fusaro
Fausto Fusaro

Reputation: 616

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

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:

Upvotes: 44

Views: 128158

Answers (12)

Nicoleee
Nicoleee

Reputation: 415

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

Upvotes: 1

Schopen Hacker
Schopen Hacker

Reputation: 322

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

Upvotes: 0

primegxy
primegxy

Reputation: 1858

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)

Upvotes: -1

Amirsalar
Amirsalar

Reputation: 729

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

Upvotes: 0

ImustAdmit
ImustAdmit

Reputation: 507

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

Upvotes: 3

Mastan Basha Shaik
Mastan Basha Shaik

Reputation: 144

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?

Upvotes: 1

ARKhan
ARKhan

Reputation: 1975

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

Upvotes: 26

JoshEM1994
JoshEM1994

Reputation: 11

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 )

Upvotes: 1

Shao
Shao

Reputation: 51

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

Upvotes: 5

Cory Brickner
Cory Brickner

Reputation: 41

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

Upvotes: 4

Carlos Pero
Carlos Pero

Reputation: 94

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).

Upvotes: 2

Gabouchet
Gabouchet

Reputation: 191

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.

Upvotes: 13

Related Questions