skip to Main Content

I’m deploying a Django project in a cPanel hosting environment (NameCheap).

NameCheap currently only supports PostgreSQL: 8.4.20.

I want to use PostgreSQL as my Django database backend but (see bold requirement):

The current psycopg2 implementation supports:

  • Python version 2.7
  • Python 3 versions from 3.4 to 3.8
  • PostgreSQL server versions from 7.4 to 12
  • PostgreSQL client library version from 9.1

Upgrading from 8.4.20 to >= 9.1 is not an option in NameCheap (shared hosting plan).

So my problem is, if I attempt to do a pip install psycopg2, I receive an error:

./psycopg/psycopg.h:30:2: error: #error "Psycopg requires
PostgreSQL client library (libpq) >= 9.1

BECAUSE PostgreSQL 8.4.20 < PostgreSQL: 9.1.

My Question Is:

Is psycopg2 the only “approved”(?) / “official” / “supported” module for Django and PostgreSQL? If not, what psycopg2 alternative package could I use and how to implement in general?

2

Answers


  1. You can install psycopg 2.6.2. Libpq >= 9.1 is required only since psycopg 2.7.

    Try pip install "psycopg2<2.7".

    Login or Signup to reply.
  2. I also tried to use PostgreSQL database with Django on Namecheap shared hosting. I faced problems in the beginning but now I am using it without a problem. Here is the procedure you can follow to use PostgreSQL database with Django on shared hosting (Although I am using psycopg2):

    1. Deploy your Django app as usual except for the database part
    2. Create a PostgreSQL database. Note its name and the username and password of the user you added to it.
    3. Launch the terminal in CPanel (You can also do this via SSH), enter the virtual environment and execute the following command to install psycopg2 (binary distribution):
        pip install psycopg2-binary
    
    1. Now edit your settings.py and add the following configurations for the database:
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'database_name',
        'USER': 'database_username',
        'PASSWORD': 'database_password',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
    

    Make sure to use 127.0.0.1 instead of localhost

    1. Your database has been configured. Restart the python app, do migrations etc.

    I am using Python 3.7 and Django 3.0

    I have also written a post about this on my blog.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search