[Django]-How do I install psycopg2 for Python 3.x?

21👍

Just run this using the terminal:

$ sudo apt-get install python3-dev

This way, you could use gcc to build the module you’re trying to use.

34👍

On Ubuntu you just run this:

sudo apt-get install python3-psycopg2

18👍

Another option that seems to provide a newer version of psycopg2 than the one in the python3-psycopg2 package (at least when I wrote this):

sudo apt-get install pip3
sudo apt-get install libpq-dev
sudo pip3 install psycopg2
👤sudo

1👍

For most operating systems, the quickest way to install Psycopg is using the wheel package available on PyPI:

$ pip install psycopg2-binary

Check:

$ pip freeze | grep -i psycopg2
psycopg2-binary==2.9.3

This will install a pre-compiled binary version of the module which does not require the build or runtime prerequisites.

Or:

$ sudo apt-get install libpq-dev
$ pip install psycopg2

Check:

$ pip freeze | grep -i psycopg2
psycopg2==2.9.3

More info about psycopg vs psycopg-binary.

Leave a comment