On my scenario, it was performed on:
ProductName: macOS
ProductVersion: 12.1
BuildVersion: 21C52
- I proceed to install the following libraries by
brewcommand:
brew install openssl libpq
export LDFLAGS="-L/opt/homebrew/opt/libpq/lib -L/opt/homebrew/opt/openssl@3/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libpq/include -I/opt/homebrew/opt/openssl@3/include"
- Proceed to install the python package
psycopg2-binary via pip3:
pip3 install psycopg2-binary
If you are wondering why it is necessary to set those specific variables, take a look in the docs of the package via brew info command:
brew info openssl
brew info libpq
When the outcome is displayed, look for this sentence:
...
For compilers to find libpq you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/libpq/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libpq/include"
...
For compilers to find openssl@3 you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"
...
Thats why, when pip is installing a package, needs a reference where to look for the libraries/compilers.
A perfect place to set this variables would be ~/.bashrc, for future installations regarding postgres and ssl:
export LDFLAGS="-L/opt/homebrew/opt/libpq/lib -L/opt/homebrew/opt/openssl@3/lib"
export CPPFLAGS="-I/opt/homebrew/opt/libpq/include -I/opt/homebrew/opt/openssl@3/include"