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
已提问 2 个月前864 查看次数
2 回答
2
已接受的回答

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
专家
已回答 2 个月前
profile picture
专家
已审核 2 个月前
profile pictureAWS
专家
已审核 2 个月前
  • 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
专家
iBehr
已回答 2 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则