Search code examples
pythonmacospip-tools

When run `pip-compile requirements.in` in macOS12 monterey using venv python-3.9.9, pg_config not found


OS: monterey macOSv12.0.1 python venv: 3.9.9

requirements.in

# To update requirements.txt, run:
#
#    pip-compile requirements.in
#
# To install in localhost, run:
#
#    pip-sync requirements.txt
#

django==3.2.10  # https://www.djangoproject.com/

psycopg2-binary==2.9.2 # https://github.com/psycopg/psycopg2

After i turn on venv, then i type pip-compile requirements.in then i get a bunch of errors about pg_config not found

This is my asciinema https://asciinema.org/a/sl9MqmrayLAR3rRxEul4mYaxw

I have tried env LDFLAGS='-L/usr/local/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib' pip-compile requirements.in but same.

Please advise.


Solution

  • I appreciate the other 2 answers from @Vishnudev and @cetver 🙏

    But I tried to install postgresql using brew install and it took a very long time and I still cannot complete after 20 mins.

    I figured this out eventually after much googling

    Here are my tech specs of my situation:

    1. monterey 12.1.0
    2. Apple silicon
    3. zsh

    Concepts

    Conceptually, what I did is :

    1. install openssl, turn on all the exports associated with that,
    2. then install libpq, turn on all the exports associated with that,
    3. then turn on python venv

    Here are my steps I took. It's entirely possible not all steps are needed. But I have limited time so here they are.

    Steps

    1. brew install openssl
    2. put the following in .zshrc export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"
    3. put the following in .zshenv
    export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
    export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"
    export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"
    
    1. source ~/.zshrc
    2. brew install libpq
    3. put the following in .zshrc export PATH="/opt/homebrew/opt/libpq/bin:$PATH"
    4. put the following in .zshenv
    export LDFLAGS="-L/opt/homebrew/opt/libpq/lib"
    export CPPFLAGS="-I/opt/homebrew/opt/libpq/include"
    export PKG_CONFIG_PATH="/opt/homebrew/opt/libpq/lib/pkgconfig"
    
    1. source ~/.zshenv
    2. Turn on venv
    3. Now the installing of psycopg2-binary should work

    Links that help me:

    1. the one abt openssl
    2. the one abt libpq