[Django]-How to install psycopg2 for django on mac

3👍

Instead of

pip install psycopg2

try

pip install psycopg2-binary

👤C S

0👍

You will need XCode to compile with gcc on macOS.
Install it with this command in the terminal:

xcode-select --install

Or you cold install it from the app store.

0👍

You should use virtualenv and Python Setup Tools/PIP to install all you packages for django.
This makes your job of package installs/upgrades very easy.

pip install virtualenv

This will install the virtualenv. Now create and activate a virtual environment using this virtualenv like this:

virtualenv <any_name_you_want_for_this_virtual_env>
e.g.
virtualenv api-venv

This will create a directory: api-venv in the current directory you are in.
Now activate this environment and then install all your packages using ‘pip’ command. This way, pip will install all packages inside this api-venv environment only.

source api-venv/bin/activate

Now the api-venv is activated. Let’s install ‘psycopg2’

pip install psycopg2

I would recommend to install django inside this venv so everything is in the venv.

pip install django

You can create as many such virtual environments as you like with different configuration.
Done!

0👍

You can try this way. First, you should install PostgreSQL through brew.

    brew install postgresql

Then you should add pg_config to PATH. You can find pg_config with.

    which pg_config

Finally, install psycopg2 with pip.

    pip install psycopg2

Leave a comment