python 3.12 on Amazon Linux 2023

0

I'm trying to build a container to run on ECS with Amazon Linux 2023 as the base image. I'd like to use Python 3.12 to run an application on the container, and I'm having a hard time getting the package manager (dnf) to find Python 3.12.

The line...

RUN dnf -y install python3.12

...in my dockerfile fails with the following error:

0.605 No match for argument: python3.12                                                                                                                                                                                                  
0.614 Error: Unable to find a match: python3.12   

How do I install Python 3.12 on Amazon Linux 2023 using dnf?

stu
gefragt vor 2 Monaten904 Aufrufe
2 Antworten
2
Akzeptierte Antwort

Why not try installing Python3.12 using pyenv as shown below?

FROM amazonlinux:2023

RUN dnf install -y git tar gcc \
                   zlib-devel bzip2-devel readline-devel \
                   sqlite sqlite-devel openssl-devel \
                   tk-devel libffi-devel xz-devel

RUN curl https://pyenv.run | bash && \
    echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc && \
    echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc && \
    echo 'eval "$(pyenv init -)"' >> ~/.bashrc && \
    source ~/.bashrc && \
    pyenv install 3.12.4 && \
    pyenv global 3.12.4
profile picture
EXPERTE
beantwortet vor 2 Monaten
profile picture
EXPERTE
überprüft vor 2 Monaten
profile pictureAWS
EXPERTE
überprüft vor 2 Monaten
  • By the way, this method takes about 6 to 7 minutes to build. Once the build is complete, you can start the container from the image and check the Python version.

    [root@ip-172-31-33-20 ~]# docker build ./
    [+] Building 367.4s (7/7) FINISHED
    
    [root@ip-172-31-33-20 ~]# docker run -it 46dccd41afb4 /bin/bash
    bash-5.2#
    bash-5.2# python -V
    Python 3.12.4
    
0

Looks like python3.11 is the latest available in the repos.

dnf list | grep python3

https://docs.aws.amazon.com/linux/al2023/ug/python.html

profile pictureAWS
EXPERTE
iBehr
beantwortet vor 2 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen