Closed jithin77 closed 3 weeks ago
To resolve the issue with the Docker build process failing during the RUN poetry install --no-root
step due to the pg_config
executable not being found when trying to install psycopg2
, you need to install the libpq-dev
package, which provides the pg_config
executable.
You can modify your Dockerfile to include the installation of libpq-dev
as follows:
# Use an official Python runtime as a parent image
FROM python:3.11-slim
# Set the working directory in the container
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
curl \
make \
libpq-dev \ # Add this line to install libpq-dev
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install Poetry
RUN curl -sSL https://install.python-poetry.org | python3 -
RUN apt-get update && apt-get install netcat-openbsd -y
# Add Poetry to PATH
ENV PATH="/root/.local/bin:$PATH"
# Copy the current directory contents into the container at /app
COPY . /app
RUN poetry lock --no-update
# Install Python dependencies
RUN poetry install --no-root
# Add wait-for-it.sh script to the container
COPY wait-for-it.sh /wait-for-it.sh
RUN chmod +x /wait-for-it.sh
# Make port 8000 available to the world outside this container
EXPOSE 8000
# Copy entrypoint script to the container
COPY startup.sh /startup.sh
RUN chmod +x /startup.sh
# RUN dos2unix startup.sh
# Run the entrypoint script
CMD ["/startup.sh"]
By adding libpq-dev
to the list of system dependencies, the pg_config
executable will be available, and the psycopg2
installation should proceed without issues [1].
To continue talking to Dosu, mention @dosu.
System Info
Latest code from repo
🐛 Describe the bug
RUN poetry install --no-root Installing dependencies from lock file
Package operations: 81 installs, 1 update, 0 removals
ChefBuildError
Backend subprocess exited when trying to invoke get_requires_for_build_wheel
running egg_info writing psycopg2.egg-info/PKG-INFO writing dependency_links to psycopg2.egg-info/dependency_links.txt writing top-level names to psycopg2.egg-info/top_level.txt
Error: pg_config executable not found.
pg_config is required to build psycopg2 from source. Please add the directory containing pg_config to the $PATH or specify the full executable path with the option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
If you prefer to avoid building psycopg2 from source, please install the PyPI 'psycopg2-binary' package instead.
For further information please check the 'doc/src/install.rst' file (also at https://www.psycopg.org/docs/install.html).
at ~/.local/share/pypoetry/venv/lib/python3.11/site-packages/poetry/installation/chef.py:164 in _prepare 160â 161â error = ChefBuildError("\n\n".join(message_parts)) 162â 163â if error is not None: â 164â raise error from None 165â 166â return path 167â 168â def _prepare_sdist(self, archive: Path, destination: Path | None = None) -> Path:
Note: This error originates from the build backend, and is likely not a problem with poetry but with psycopg2 (2.9.9) not supporting PEP 517 builds. You can verify this by running 'pip wheel --no-cache-dir --use-pep517 "psycopg2 (==2.9.9)"'.