Search code examples
djangopostgresqlmacospsycopg2

Psycopg2 installation error on mac: command 'clang' failed with status 1


I can't install psycopg2 on my m1 Mac. I tried to reinstall openssl with brew. I tried a lot of thing but nothing changed. The error log is super long so I couldn't understand what is wrong. I am facing up with this error when I try to pip install psycopg2 Waiting for your help. Here is the full error log: https://wtools.io/paste-code/b4jG


Solution

  • The error is happening because it seems to be having some problem with ssl. I used different answers from a similar question to solve it for myself:

    1. Install openssl if you don't have:

      brew install openssl

    2. Check the path where openssl got installed using:

      brew --prefix openssl

    3. Use output from above and add LD flag when running the pip command, for example in my case the output was /opt/homebrew/opt/openssl@1.1 so I did the following:

      LDFLAGS="-I/opt/homebrew/opt/openssl@1.1/include -L/opt/homebrew/opt/openssl@1.1/lib" pip install psycopg2

    And that did the trick for me.