Install the PostGreSQL driver, psycopg2, with Python with a Mac

Mac is a good computer but seems to be weird when you are attacking some install.

I had error installing the PostGreSQL drivers for python. 

Typing a :

$ pipenv install psycopg2


$ pip install psycopg2 was leading to compilation error…

Problems seems to be with Mac (as usual) and Path. (as Usual)

Then was solved on my side doing that :

1 – I presume you have PostGreSQL installed via a homebrew install …

if not :

$ brew install postgresql

2 – I presume you have started PostGree too…

If not, :

$ pg_ctl -D /usr/local/var/postgres start

3 – Install Opensll

$ brew install openssl

If you have already installed it, re-install 

$ brew reinstall openssl

4 – Find the path of pg_config

$ find / -name pg_config  2>/dev/nul

5 – Check something like my path :

$ export PATH=$PATH:/usr/local/Cellar/postgresql/11.5_1/bin/pg_config

6 – Do the same thing with the lib ssl :

$ export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

Ok now, you should be OK typing :

$ pipenv install psycopg2 if you use pipenv


$ pip install psycopg2 

it could pip3 instead of pip if you are not working under virtual environnement and you have installed the python 3 version keeping the python2 on the Mac.

Inside a virtual environnement, the pip is linked to python3 by default.