From 4651dffc54e2d5e1105ffd3d46a613adf2650895 Mon Sep 17 00:00:00 2001 From: Kiro Agent <244629292+kiro-agent@users.noreply.github.com> Date: Tue, 27 Jan 2026 19:20:55 +0000 Subject: [PATCH] Migrate backend from Python 3.9 to Python 3.11 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Dockerfile Changes: - Updated Python version from 3.9.23 to 3.11.9 - Updated all python3.9 references to python3.11 - Updated libpython search patterns ## requirements.txt Changes: - scikit-learn: 1.0.2 → 1.3.2 (required for Python 3.11 support) - pyyaml: 5.4.1 → 6.0.1 (better Python 3.11 compatibility) - numpy: 1.24.3 → 1.26.4 (optimized for Python 3.11) - grpcio-tools: 1.51.1 → 1.56.2 (aligned with grpcio version) - Added notes for dlr and Jetson.GPIO regarding Python 3.11 verification ## Packages requiring manual verification: - dlr (Neo DLR): May need custom build for Python 3.11 - Jetson.GPIO: Verify compatibility on your Jetson device Co-authored-by: rajjainl <182391521+rajjainl@users.noreply.github.com> --- src/backend/Dockerfile | 20 ++++++++++---------- src/backend/requirements.txt | 14 ++++++++++---- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/backend/Dockerfile b/src/backend/Dockerfile index ae945ec..dd6beda 100644 --- a/src/backend/Dockerfile +++ b/src/backend/Dockerfile @@ -3,15 +3,15 @@ FROM public.ecr.aws/ubuntu/ubuntu:${OS} ENV DEBIAN_FRONTEND=noninteractive RUN apt-get update && apt-get install -y software-properties-common wget build-essential libffi-dev zlib1g-dev libssl-dev libsqlite3-dev gdb RUN apt-get update -RUN wget https://www.python.org/ftp/python/3.9.23/Python-3.9.23.tgz -RUN tar -xzf Python-3.9.23.tgz -RUN cd Python-3.9.23 && \ +RUN wget https://www.python.org/ftp/python/3.11.9/Python-3.11.9.tgz +RUN tar -xzf Python-3.11.9.tgz +RUN cd Python-3.11.9 && \ ./configure --enable-optimizations --enable-shared && \ make -j$(nproc) && \ make install -RUN find / -name "libpython3.9.so.1.0" -print -RUN update-alternatives --install /usr/local/bin/python3 python3 /usr/local/bin/python3.9 1 \ - && update-alternatives --set python3 /usr/local/bin/python3.9 +RUN find / -name "libpython3.11.so.1.0" -print +RUN update-alternatives --install /usr/local/bin/python3 python3 /usr/local/bin/python3.11 1 \ + && update-alternatives --set python3 /usr/local/bin/python3.11 RUN add-apt-repository ppa:ubuntu-toolchain-r/test -y && \ apt-get update && \ @@ -30,7 +30,7 @@ COPY edge_ml1_p_camera_management ./edge_ml1_p_camera_management COPY edgeagent ./edgeagent RUN ./edge_ml1_p_camera_management/prereqs_install.sh RUN ./edge_ml1_p_camera_management/install_aravis.sh -RUN python3.9 -m grpc_tools.protoc --proto_path=./edgeagent --python_out=. --grpc_python_out=. edgeagent/edge-agent.proto +RUN python3.11 -m grpc_tools.protoc --proto_path=./edgeagent --python_out=. --grpc_python_out=. edgeagent/edge-agent.proto RUN apt update -y RUN apt-get install libssl1.1 -y RUN apt update -y @@ -39,7 +39,7 @@ RUN if [ "$OS" = "18.04" ] ; then \ apt install libavcodec-extra57i -y; \ fi -RUN find / -name "libpython3.9.so.1.0" -print +RUN find / -name "libpython3.11.so.1.0" -print RUN apt clean -y @@ -64,7 +64,7 @@ COPY alembic.ini ./ COPY dda_triton ./dda_triton COPY lyra_anomalies_mask_utils ./lyra_anomalies_mask_utils COPY lyra_science_processing_utils ./lyra_science_processing_utils -CMD ["python3.9", "app.py"] +CMD ["python3.11", "app.py"] # Temporary to fix CVE-2024-24806 and CVE-2024-0553 until slim-buster base image is fixed RUN apt-get update \ @@ -81,7 +81,7 @@ RUN apt-get update \ COPY edgemlsdk ./edgemlsdk RUN ./edge_ml1_p_camera_management/install_edgemlsdk.sh COPY dlr_disable_phone_home.py ./ -RUN python3.9 dlr_disable_phone_home.py +RUN python3.11 dlr_disable_phone_home.py #TODO:change to user to scope the permission. Currently needed to persist the TinyDB data USER root diff --git a/src/backend/requirements.txt b/src/backend/requirements.txt index 47c2730..5bac6b2 100644 --- a/src/backend/requirements.txt +++ b/src/backend/requirements.txt @@ -5,14 +5,18 @@ opencv-python urllib3==2.2.3 requests==2.32.3 python-dateutil==2.8.2 +# Note: Jetson.GPIO - verify compatibility with Python 3.11 on your Jetson device Jetson.GPIO==2.0.21 awsiotsdk==1.11.9 marshmallow==3.19.0 -pyyaml==5.4.1 +# Upgraded for Python 3.11 compatibility +pyyaml==6.0.1 grpcio==1.56.2 -grpcio-tools==1.51.1 +# Aligned with grpcio version +grpcio-tools==1.56.2 jsonschema==4.17.3 -numpy==1.24.3 +# Upgraded for better Python 3.11 support and optimization +numpy==1.26.4 Pillow==10.3.0 pycairo==1.23.0 PyGObject==3.42.2 @@ -21,6 +25,7 @@ psutil==5.9.5 fastapi==0.109.2 uvicorn==0.23.2 pydantic==2.1.1 +# Note: dlr (Neo DLR) - verify Python 3.11 wheel availability; may require custom build dlr==1.10.0 asgi-correlation-id==4.2.0 structlog==22.1.0 @@ -29,4 +34,5 @@ Deprecated==1.2.14 sqlalchemy==2.0.21 alembic==1.12.1 httpx==0.24.1 -scikit-learn==1.0.2 +# Upgraded for Python 3.11 support (minimum version 1.1.0 required for 3.11) +scikit-learn==1.3.2