Ubuntu 22.04 安装Python 3.12

1,334 阅读1分钟

Update Your Package List

apt update

Install Essential Dependencies

apt install -y software-properties-common build-essential libffi-dev libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev libffi-dev libssl-dev 

Add DeadSnakes PPA

add-apt-repository ppa:deadsnakes/ppa 

Install Python 3.12

apt update
apt install -y python3.12 python3.12-venv  

Verify the Installation

python3.12 --version 

Set Python 3.12 as the Default

update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 312 
update-alternatives --config python3 

Install Pip for Python 3.12

apt install python3.12-distutils 
wget https://bootstrap.pypa.io/get-pip.py 
python3.12 get-pip.py 

Clean Up (Optional)

apt autoremove