[Python] building Docker image ModuleNotFoundError: No module named 'distutils'

Discussão em 'Python' iniciado por Stack, Março 6, 2025.

  1. Stack

    Stack Membro Participativo

    Im new on Dockers. I tried Ai to get a solution but moving nowhere. Context: Im trying to build the image given this docker file ( below) and i keep getting " ModuleNotFoundError: No module named 'distutils'" I appreciate any help. Thx !

    # Step 1: Use Ubuntu 20.04 as base
    FROM ubuntu:20.04

    # Step 2: Set non-interactive frontend
    ARG DEBIAN_FRONTEND=noninteractive

    # Step 3: Ensure Python logs everything immediately
    ENV PYTHONUNBUFFERED=1

    # Step 4: Install Python 3.12.8 from deadsnakes PPA (INCLUDE venv & dev)
    RUN apt-get update && apt-get install -y software-properties-common
    RUN add-apt-repository ppa:deadsnakes/ppa && apt-get update
    RUN apt-get install -y python3.12 python3-pip python3.12-venv python3.12-dev

    # Step 5: Upgrade pip and install setuptools, wheel
    RUN python3.12 -m pip install --no-cache-dir --upgrade pip setuptools wheel

    # Step 6: Install FastAPI and Uvicorn
    RUN python3.12 -m pip install --no-cache-dir fastapi==0.115.6 uvicorn==0.33.0

    # Step 7: Create a working directory
    WORKDIR /app

    # Step 8: Copy everything from the current directory into the working directory
    COPY . /app

    # Step 9: Expose port 8000
    EXPOSE 8000

    # Step 10: Define ENTRYPOINT to use Uvicorn
    ENTRYPOINT ["uvicorn"]

    # Step 11: CMD command to start FastAPI app
    CMD ["app.main:app", "--host", "0.0.0.0", "--port", "8000"]


    im trying to build a docker image, i tried changing the order i create layers but i keep getting the same error.

    Continue reading...

Compartilhe esta Página