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:
Pip install error in Mac OS(error: command '/usr/bin/clang' failed with exit status 1)
Mac OS Mojave installation error - error: command 'clang' failed with exit status 1
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.
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
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
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
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/
Duplicate your Terminal rename it to "Rosetta Terminal" or similar
Get Info on the new app, and check the box for "Open using Rosetta"
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).
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 )
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?
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
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
I'm using virtualenv and I need to install "psycopg2".
I have done the following:
pip install http://pypi.python.org/packages/source/p/psycopg2/psycopg2-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160
And I have the following messages:
Downloading/unpacking http://pypi.python.org/packages/source/p/psycopg2/psycopg2
-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160
Downloading psycopg2-2.4.tar.gz (607Kb): 607Kb downloaded
Running setup.py egg_info for package from http://pypi.python.org/packages/sou
rce/p/psycopg2/psycopg2-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160
Error: pg_config executable not found.
Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
Complete output from command python setup.py egg_info:
running egg_info
creating pip-egg-info\psycopg2.egg-info
writing pip-egg-info\psycopg2.egg-info\PKG-INFO
writing top-level names to pip-egg-info\psycopg2.egg-info\top_level.txt
writing dependency_links to pip-egg-info\psycopg2.egg-info\dependency_links.txt
writing manifest file 'pip-egg-info\psycopg2.egg-info\SOURCES.txt'
warning: manifest_maker: standard file '-c' not found
Error: pg_config executable not found.
Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in C:\Documents and Settings\anlopes\Application Data\pip\p
ip.log
My question, I only need to do this to get the psycopg2 working?
python setup.py build_ext --pg-config /path/to/pg_config build ...
Note: Since a while back, there are binary wheels for Windows in PyPI, so this should no longer be an issue for Windows users. Below are solutions for Linux, Mac users, since lots of them find this post through web searches.
Option 1
Install the psycopg2-binary PyPI package instead, it has Python wheels for Linux and Mac OS.
pip install psycopg2-binary
Option 2
Install the prerequsisites for building the psycopg2 package from source:
Debian/Ubuntu
Python 3
sudo apt install libpq-dev python3-dev
You might need to install python3.8-dev or similar for e.g. Python 3.8.
Python 2
sudo apt install libpq-dev python-dev
If that's not enough, try
sudo apt install build-essential
or
sudo apt install postgresql-server-dev-all
as well before installing psycopg2 again.
CentOS 6
See Banjer's answer
macOS
See nichochar's answer
On CentOS, you need the postgres dev packages:
sudo yum install python-devel postgresql-devel
That was the solution on CentOS 6 at least.
If you're on a mac you can use homebrew
brew install postgresql
And all other options are here: http://www.postgresql.org/download/macosx/
On Mac Mavericks with Postgres.app version 9.3.2.0 RC2 I needed to use the following code after installing Postgres:
sudo PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin pip install psycopg2
I recently configured psycopg2 on a windows machine. The easiest install is using a windows executable binary. You can find it at http://stickpeople.com/projects/python/win-psycopg/.
To install the native binary in a virtual envrionment, use easy_install:
C:\virtualenv\Scripts\> activate.bat
(virtualenv) C:\virtualenv\Scripts\> easy_install psycopg2-2.5.win32-py2.7-pg9.2.4-release.exe
For Python 3 you should use sudo apt-get install libpq-dev python3-dev under Debian.
This is what worked for me (On RHEL, CentOS:
sudo yum install postgresql postgresql-devel python-devel
And now include the path to your postgresql binary dir with you pip install:
sudo PATH=$PATH:/usr/pgsql-9.3/bin/ pip install psycopg2
Make sure to include the correct path. Thats all :)
UPDATE: For python 3, please install python3-devel instead of python-devel
The answers so far are too much like magic recipes. The error that you received tells you that pip cannot find a needed part of the PostgreSQL Query library. Possibly this is because you have it installed in a non-standard place for your OS which is why the message suggests using the --pg-config option.
But a more common reason is that you don't have libpq installed at all. This commonly happens on machines where you do NOT have PostgreSQL server installed because you only want to run client apps, not the server itself. Each OS/distro is different, for instance on Debian/Ubuntu you need to install libpq-dev. This allows you to compile and link code against the PostgreSQL Query library.
Most of the answers also suggest installing a Python dev library. Be careful. If you are only using the default Python installed by your distro, that will work, but if you have a newer version, it could cause problems. If you have built Python on this machine then you already have the dev libraries needed for compiling C/C++ libraries to interface with Python. As long as you are using the correct pip version, the one installed in the same bin folder as the python binary, then you are all set. No need to install the old version.
If you using Mac OS, you should install PostgreSQL from source.
After installation is finished, you need to add this path using:
export PATH=/local/pgsql/bin:$PATH
or you can append the path like this:
export PATH=.../:usr/local/pgsql/bin
in your .profile file or .zshrc file.
This maybe vary by operating system.
You can follow the installation process from http://www.thegeekstuff.com/2009/04/linux-postgresql-install-and-configure-from-source/
On Debian/Ubuntu:
First install and build dependencies of psycopg2 package:
# apt-get build-dep python-psycopg2
Then in your virtual environment, compile and install psycopg2 module:
(env)$ pip install psycopg2
Run below commands and you should be fine
$ apt-get update
$ apt install python3-dev libpq-dev
$ pip3 install psycopg2
I've done this before where in windows you install first into your base python installation.
Then, you manually copy the installed psycopg2 to the virtualenv install.
It's not pretty, but it works.
Before you can install psycopg2 you will need to install the python-dev package.
If you're working from Linux (and possibly other systems but i can't speak from experience) you will need to make sure to be quite exact about what version of python your running when installing the dev package.
For example when I used the command:
sudo apt-get install python3-dev
I still ran into the same error when trying to
pip install psycopg2
As I am using python 3.7 I needed to use the command
sudo apt-get install python3.7-dev
Once I did this I ran into no more issues. Obviously if your on python version 3.5 you would change that 7 to a 5.
Besides installing the required packages, I also needed to manually add PostgreSQL bin directory to PATH.
$vi ~/.bash_profile
Add PATH=/usr/pgsql-9.2/bin:$PATH before export PATH.
$source ~/.bash_profile
$pip install psycopg2
For MacOS,
Use the below command to install psycopg2, works like charm!!!
env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install psycopg2
On windows XP you get this error if postgres is not installed ...
I installed Postgresql92 using the RedHat / CentOS repository on PG's downloads site http://www.postgresql.org/download/linux/redhat/
To get pg_config, I had to add /usr/pgsql-9.2/bin to PATH.
On Fedora 24: For Python 3.x
sudo dnf install postgresql-devel python3-devel
sudo dnf install redhat-rpm-config
Activate your Virtual Environment:
pip install psycopg2
Psycopg2 Depends on Postgres Libraries.
On Ubuntu You can use:
apt-get install libpq-dev
Then:
pip install psycopg2
I've been battling with this for days, and have finally figured out how to get the "pip install psycopg2" command to run in a virtualenv in Windows (running Cygwin).
I was hitting the "pg_config executable not found." error, but I had already downloaded and installed postgres in Windows. It installed in Cygwin as well; running "which pg_config" in Cygwin gave "/usr/bin/pg_config", and running "pg_config" gave sane output -- however the version installed with Cygwin is:
VERSION = PostgreSQL 8.2.11
This won't work with the current version of psycopg2, which appears to require at least 9.1. When I added "c:\Program Files\PostgreSQL\9.2\bin" to my Windows path, the Cygwin pip installer was able to find the correct version of PostgreSQL, and I was able to successfully install the module using pip. (This is probably preferable to using the Cygwin version of PostgreSQL anyway, as the native version will run much quicker).
On OpenSUSE 13.2, this fixed it:
sudo zypper in postgresql-devel
For lowly Windows users were stuck having to install psycopg2 from the link below, just install it to whatever Python installation you have setup. It will place the folder named "psycopg2" in the site-packages folder of your python installation.
After that, just copy that folder to the site-packages directory of your virtualenv and you will have no problems.
here is the link you can find the executable to install psycopg2
http://www.lfd.uci.edu/~gohlke/pythonlibs/
On Ubuntu I just needed the postgres dev package:
sudo apt-get install postgresql-server-dev-all
*Tested in a virtualenv
I could install it in a windows machine and using Anaconda/Spyder with python 2.7 through the following commands:
!pip install psycopg2
Then to establish the connection to the database:
import psycopg2
conn = psycopg2.connect(dbname='dbname',host='host_name',port='port_number', user='user_name', password='password')
In Arch base distributions:
sudo pacman -S python-psycopg2
pip2 install psycopg2 # Use pip or pip3 to python3
On OSX 10.11.6 (El Capitan)
brew install postgresql
PATH=$PATH:/Library/PostgreSQL/9.4/bin pip install psycopg2
On OSX with macports:
sudo port install postgresql96
export PATH=/opt/local/lib/postgresql96/bin:$PATH
if pip is not working than you can download .whl file from here https://pypi.python.org/pypi/psycopg2
extract it..
than python setup.py install
I was having this problem, the main reason was with 2 equal versions installed. One by postgres.app and one by HomeBrew.
If you choose to keep only the APP:
brew unlink postgresql
pip3 install psycopg2
Installation on MacOS
Following are the steps, which worked for me and my team members while installing psycopg2 on Mac OS Big Sur and which we have extensively tested for Big Sur. Before starting make sure you have the Xcode command-line tool installed. If not, then install it from the Apple Developer site. The below steps assume you have homebrew installed. If you have not installed homebrew then install it. Last but not the least, it also assumes you already have PostgreSQL installed in your system, if not then install it. Different people have different preferences but the default installation method on the official PostgreSQL site via Enterprise DB installer is the best method for the majority of people.
Put up the linkage to pg_config file in your .zshrc file by: export PATH="$PATH:/Library/PostgreSQL/12/bin:$PATH". This way you are having linkage with the pg_config file in the /Library/PostgreSQL/12/bin folder. So if your PostgreSQL installation is via other means, like Postgres.app or Postgres installation via homebrew, then you need to have in your .zshrc file the link to pg_config file from the bin folder of that PostgreSQL installation as psycopg2 relies on that.
Install OpenSSL via Homebrew using the command brew install openssl. The reason for this is that libpq, the library which is the basis of psycopg2, uses openssl - psycopg2 doesn't use it directly. After installing put the following commands in your .zshrc file:
export PATH="/usr/local/opt/openssl#1.1/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/openssl#1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl#1.1/include"
By doing this you are creating necessary linkages in your directory. These commands are suggested by brew while you install openssl and have been directly picked up from there.
Now comes the most important step, which is to install libpq using the command brew install libpq. This installs libpq library. As per the documentation
libpq is the C application programmer's interface to PostgreSQL. libpq is a set of library functions that allow client programs to pass queries to the PostgreSQL backend server and to receive the results of these queries.
Link libpq using brew link libpq, if this doesn't work then use the command: brew link libpq --force.
Also put in your .zshrc file the following export PATH="/usr/local/opt/libpq/bin:$PATH". This creates all the necessary linkages for libpq library .
Now restart the terminal or use the following command source ~/.zshrc.
This works even when you are working in conda environment.
N.B. pip install psycopg2-binaryshould be avoided because as per the developers of the psycopg2 library
The use of the -binary packages in production is discouraged because in the past they proved unreliable in multithread environments. This might have been fixed in more recent versions but I have never managed to reproduce the failure.
I am using Azure to create an Ubuntu server 18.04. The python3 default version in this VM is 3.6.9. I tried to install python3-pip, then install Tensorflow version 1.15.0 by command: sudo pip3 install Tensorflow==1.15.0.
However I got this error: No matching distribution found for tensorflow==1.15.0
I really don't know how to fix it. On my Windows PC, I got the same error while using python3.7, then I change to use python3.6.5 and everythings is fine. So that I think maybe I should try to install python 3.6.5 on Ubuntu VM. But again, this time, I can't install correctly python 3.6.5 on my Ubuntu server.
Can you please help me to fix it. I am just a newbie and honestly, I am not really good with Ubuntu.
Thank you so much.
I had the same issue.
A simple upgrade of pip to the latest version by:
sudo -H pip3 install --upgrade pip
sudo -H pip2 install --upgrade pip
solved the problem for me. Checkout https://askubuntu.com/questions/712339/how-to-upgrade-pip-to-latest for details how to upgrade pip.
After checking it seems the pip3 version shipped with Ubuntu defaults to pip 9.0.1. However, this version seems to supports only up to Tensorflow 1.14.
I would also strongly suggest to use virtual environments like Anaconda in order not to mess up your system python.
E.g.: https://docs.anaconda.com/anaconda/install/linux/
These are the list of files for TensorFlow 1.15
This command would work:
pip3 install tensorflow==1.15.0
I do see the manylinux wheel file for Ubuntu.
What CPU model and pip version are you using?
Debugging:
pip3 -v install tensorflow==1.15.0 | grep Found | more
Can help you see which platform and tags pip3 is trying to find in wheel files.
In the past I also have seen issue with pip default version (9.0.1), make sure you are running a recent version (e.g. pip-20.0.2):
apt install python3-pip && pip3 install --upgrade pip
I installed xcode dev tools first using
%xcode-select --install
then I installed Homebrew using
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
then I did
%brew install python3
%pip3 install pipenv
but when I call
%pip3
I get
% pip3
Traceback (most recent call last):
File "/Library/Developer/CommandLineTools/usr/bin/pip3", line 10, in <module>
sys.exit(main())
TypeError: 'module' object is not callable
This is where it says my pip3 and python3 are located
% which pip3
/usr/bin/pip3
% which python3
/usr/bin/python3
Can someone please help me solve this problem. I am trying to learn to program but I can't continue without fixing this
MacOS Catalina ships with it's own versions of python3 and pip3, so this is probably conflicts between macOS and Brew-installed Python libraries. I solved similar issues by no longer using Brew for anything related to Python.
My recommendation: From a fresh install of Catalina, run sudo pip3 install pipenv. Create a separate directory for each project you work on, and run pipenv shell from that directory every time you work on it. Don't ever bother installing any packages system-wide, and don't overwrite macOS's Python. Anything you do, do inside a Pipenv managed virtual environment -- only install packages via pipenv install <pkg>.
Doing all this will keep the right version of the Python binary and all related packages inside a directory inside ~/.local/share/virtualenvs/ for each project. This way, future macOS updates shouldn't every break dependencies.
I had a similar problem after upgrading to Catalina since I was already using homebrew and Python/pipenv stopped to work as expected. My Python crashed every time, I ran pipenv install with an error described in this developer.apple.com thread. The answer by Mickey Ristroph sounds like a okay'ish workaround, but it doesn't really solve the problem.
I want to be able to use homebrew for all my MacOS installed software - including Python. But there was help, since the problem was the usage of a wrong version libcrypto dylib version. To fix the issue, update & upgrade brew packages and be sure openssl is installed:
brew update && brew upgrade && brew install openssl
Then we create new symbolic links to the homebrew installed libssl.dylib and libcrypto.dylib libraries:
# go to homebrew installed openssl dir:
cd /usr/local/Cellar/openssl/1.0.2t/lib
sudo cp libssl.1.0.0.dylib libcrypto.1.0.0.dylib /usr/local/lib/
cd /usr/local/lib
# if there are links already, you may backup them:
mv libssl.dylib libssl_bak.dylib
mv libcrypto.dylib libcrypto_bak.dylib
# now create new symbolic links:
sudo ln -s libssl.1.0.0.dylib libssl.dylib
sudo ln -s libcrypto.1.0.0.dylib libcrypto.dylib
Now my homebrew installed Python (and pipenv) works like a charm again.
You need to change the raw command used to install libraries and supports in macOS Catalina to this:
python3 -m pip install pipenv
(instead of pip3 install pipenv)
I am running python 3.6 on windows and am attempting to install Shapely using
pip install shapely==1.6b2
It is giving me the following errors
Command "python setup.py egg_info" failed with error code 1 in C:\Users\Cameron\AppData\Local\Temp\pip-build-242ae_ih\shapely\
I have seen the other posts about this issue and have tried:
pip install --upgrade setuptools
pip install ez_setup
easy_install -U setuptools
Nothing seems to work and I am not sure what to do next. Any advice would be appreciated.
Thanks
You may try to use the binary from this unofficial site. Just use pip install {wheel file name} to install it.
Shapely‑1.5.17‑cp36‑cp36m‑win32.whl (32-bit)
Shapely‑1.5.17‑cp36‑cp36m‑win_amd64.whl (64-bit)
Hope this would make the installation easier.
I had a similar error for installing shapely-1.5.17 via pip install shapely, and installing this made the pip install command work thereafter:
sudo apt-get install libgeos-dev
As of 2020, you can now simply install Shapely for Windows with:
pip install shapely
(you many need --upgrade to get at least version 1.7.0, when binary wheels were added for Windows)