Hello Fam!

I'm currently going through djangoforprofessional tutorial and I've been 
trying to resolve an error related to installing psycopg2 for postgres in a 
docker container.

After setting up Dockerfile, requirements.txt, and docker-compose.yml which 
is shown below, I entered this command: docker-compose up -d --build
and the returned output (error) is shown below.

I have tried this command in Dockerfile: RUN pip install --user 
psycopg2==2.9.5 
I got the command on StackOverflow but still didn't resolve the issue.

Thank you very much in advance.

*Error Output*
#0 23.39 Collecting psycopg2==2.9.5
#0 23.55   Downloading psycopg2-2.9.5.tar.gz (384 kB)
#0 25.11      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 384.3/384.3 kB 246.3 
kB/s eta 0:00:00
#0 25.20   Preparing metadata (setup.py): started
#0 26.74   Preparing metadata (setup.py): finished with status 'error'
#0 26.78   error: subprocess-exited-with-error
#0 26.78
#0 26.78   × python setup.py egg_info did not run successfully.
#0 26.78   │ exit code: 1
#0 26.78   ╰─> [25 lines of output]
#0 26.78       
/usr/local/lib/python3.12/site-packages/setuptools/config/setupcfg.py:508: 
SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use 
license_files instead.
#0 26.78         warnings.warn(msg, warning_class)
#0 26.78       running egg_info
#0 26.78       creating /tmp/pip-pip-egg-info-g5ko86oj/psycopg2.egg-info
#0 26.78       writing 
/tmp/pip-pip-egg-info-g5ko86oj/psycopg2.egg-info/PKG-INFO
#0 26.78       writing dependency_links to 
/tmp/pip-pip-egg-info-g5ko86oj/psycopg2.egg-info/dependency_links.txt
#0 26.78       writing top-level names to 
/tmp/pip-pip-egg-info-g5ko86oj/psycopg2.egg-info/top_level.txt
#0 26.78       writing manifest file 
'/tmp/pip-pip-egg-info-g5ko86oj/psycopg2.egg-info/SOURCES.txt'
#0 26.78
#0 26.78       Error: pg_config executable not found.
#0 26.78
#0 26.78       pg_config is required to build psycopg2 from source.  Please 
add the directory
#0 26.78       containing pg_config to the $PATH or specify the full 
executable path with the
#0 26.78       option:
#0 26.78
#0 26.78           python setup.py build_ext --pg-config /path/to/pg_config 
build ...
#0 26.78
#0 26.78       or with the pg_config option in 'setup.cfg'.
#0 26.78
#0 26.78       If you prefer to avoid building psycopg2 from source, please 
install the PyPI
#0 26.78       'psycopg2-binary' package instead.
#0 26.78
#0 26.78       For further information please check the 
'doc/src/install.rst' file (also at
#0 26.78       <https://www.psycopg.org/docs/install.html>).
#0 26.78
#0 26.78       [end of output]
#0 26.78
#0 26.78   note: This error originates from a subprocess, and is likely not 
a problem with pip.
#0 26.78 error: metadata-generation-failed
#0 26.78
#0 26.78 × Encountered error while generating package metadata.
#0 26.78 ╰─> See above for output.
#0 26.78
#0 26.78 note: This is an issue with the package mentioned above, not pip.
#0 26.78 hint: See above for details.
------
failed to solve: executor failed running [/bin/sh -c pip install -r 
requirements.txt]: exit code: 1

*requirements.txt file*
asgiref==3.5.2
Django==4.1.2
psycopg2==2.9.5
sqlparse==0.4.3
tzdata==2022.5

*Dockerfile*
# Pull Base Image

FROM python:3.12.0a1-slim-bullseye

# Set Environment Variables

ENV PIP_DISABLE_PIP_VERSION_CHECK 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# Set Work Directory

WORKDIR /code

# Install Dependencies

COPY ./requirements.txt .
RUN pip install -r requirements.txt

# Copy Project

COPY . .

*docker-compose.yml*
version: '3.9'
services:
  web:
    build: .
    command: python /code/manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports: 
      - "8000:8000"
    depends_on:
      - db
  db:
    image: postgres:13
    volumes:
      - postgres_data:/var/lib/postgresql/data/
    environment:
      - "POSTGRES_HOST_AUTH_METHOD=trust"
volumes:
  postgres_data:



C:\Users\adede\wdev\djangoP\django-docker-postgre>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bb79d32c-e0f8-4db1-9e94-e133e61f443bn%40googlegroups.com.

Reply via email to