ImproperlyConfigured Error loading psycopg2 module No module named psycopg2

0 votes

I'm using docker-compose on Ubuntu 20.04. I have this docker-compose.yml file -- two services, a PostGres DB and a Python/Django app

version: "3.3"
   
services:
    pgdb:
        image: postgres
        container_name: postgres-Django
        ports:
            - 5433:5432
        environment:
        - POSTGRES_DB=postgres
        - POSTGRES_USER=userName
        - POSTGRES_PASSWORD=Password
    django:
        build: .
        container_name: django
        command: python manage.py runserver 0.0.0.0:8000
        volumes:
            - .:/vol/app
        ports:
            - "8000:8000"
        environment:
            DEBUG: 'true'
        depends_on:
            - pgdb
   This is the Dockerfile used to build the Python/Django container

FROM python:3.8-alpine

ADD . /app

WORKDIR  /app

COPY ./requirements.txt /app/requirements.txt

RUN python -m pip install -r requirements.txt

COPY . /app

Requirements.txt file content

Django==2.2
gunicorn==20.0.4
psycopg2-binary==2.8.6
psycopg2==2.8.6

Python setting.py file DB related content:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'postgres',
         'USER': 'postgres',
         'PASSWORD': 'admin',
         'HOST': 'pgdb',
         'PORT': 5432
    }
}

Note: HOSTNAME pgdb is the same written in docker-compose postgres service

When I execute command "docker-compose run django(django app service name) python manage.py migrate", It throws exception "psycopg2 module not found" even its available in txt file and same django app configurations working fine when execute locally.

I also tried by installing dependent libraries "libpq-dev and python3-psycopg2" but no luck

Any help please how to get rid of this problem?

Mar 8, 2021 in Python by Sadaf

edited Mar 4 10 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP