Install psycopg2 en Apple M1

Sebastián Vidal Aedo
1 min readNov 23, 2022

--

M1, you’re so cool, but sometimes you get complicated with dependencies… like psycopg2 :(

I am currently working with a Django project. I think everything will work out of the box (you just need python on the machine), but that wasn't true…

When I run

pip install -r requirements.txt

I get an error associated with the psycopg2 installation process. This doesn't happen on my other laptop, but on the M1 it does.

How to solve?

You may have some of these programs installed on your laptop, if this is the case you can ignore them and install only the ones you don't have. Here is the long list of steps:

  1. Xcode
xcode-select - install

2. Homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

3. Postgersql

brew install postgresql

4. Install Openssl and linked

brew install openssl
brew link openssl

5. Set up env variables flags

export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"

6. Install the lib

pip install psycopg2-binary

--

--

No responses yet