Skip to main content
  1. Note/

Resolve `psycopg2` Install Error on MacOS

·1 min· ·
The cover is from the official psycopg documentation.

Common Issues When Installing psycopg2 on MacOS
#

brew install libpq --build-from-source
brew install openssl

Add the following environment variables to your dotfiles or ~/.zshrc (depending on the shell you are using):

export LDFLAGS="-L$(brew --prefix openssl)/lib"
export CPPFLAGS="-I$(brew --prefix openssl)/include"
export PKG_CONFIG_PATH="$(brew --prefix openssl)/lib/pkgconfig"

Then, you should be able to install psycopg2:

pip install psycopg2

Related