The article is translated using AI.
Environment
Debian 11 arm64
Python 3.12.4
Other systems and Python versions are similar.
Prerequisites
First, update apt.
sudo apt updateInstall missing dependencies.
sudo apt build-dep python3
sudo apt install -y build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libgdbm-dev libnss3-dev liblzma-dev tk-dev libssl-dev libffi-dev
# May be needed
sudo apt install opensslInstallation
Download the source code from the Python official website.
wget https://www.python.org/ftp/python/3.12.4/Python-3.12.4.tgzExtract the source code and enter the directory.
tar -zxvf Python-3.12.4.tgz
cd Python-3.12.4Generate the Makefile.
./configure \
--enable-optimizations \
--with-system-ffi \
--with-ssl \
--enable-ipv6 \
--enable-shared CFLAGS=-fPIC \
--prefix=/usr/local/python3.12.4 \
ac_cv_file__dev_ptmx=no \
ac_cv_file__dev_ptc=noCompile.
Use the-jflag to speed up compilation, wherenprocis the number of CPU cores.
make -j $(nproc)
# Or
make -j 2Install.
# Install
make install
# Install shared libraries
cp /usr/local/python3.12.4/lib/libpython3* /usr/lib/aarch64-linux-gnu/Post-installation
Set environment variables.
Edit the profile configuration file.
vim /etc/profileAdd the following at the end:
export PATH=/usr/local/python3.12.4/bin:$PATHMake the environment variables take effect.
source /etc/profileVerify the installation.
python3 --versionUninstallation
rm -rf /usr/local/python3.12.4
rm -rf /usr/lib/aarch64-linux-gnu/libpython3*References: https://blog.iamsjy.com/2024/07/27/compile-and-install-python-3.12.4-on-debian-11-arm64/ https://chatgpt.com/