Setup Python environment

linux

Install Python 3.12 on Ubuntu 22.04

  • Manually build Python 3.12 from the source code
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    apt install -y build-essential libssl-dev zlib1g-dev libbz2-dev \
    libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
    xz-utils tk-dev libffi-dev liblzma-dev python3-openssl git

    wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz
    tar -xf Python-3.12.0.tgz
    cd Python-3.12.0
    ./configure --enable-optimizations
    make -j 8
    make altinstall
  • Install Python 3.12 from the deadsnakes PPA
    1
    2
    3
    apt install software-properties-common -y
    add-apt-repository ppa:deadsnakes/ppa
    apt update -y
  • pip
    1
    curl -sS https://bootstrap.pypa.io/get-pip.py | python3.12
  • set python3.12 default
    1
    2
    sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.12 20
    sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 20