All Products
Search
Document Center

Elastic Compute Service:Deploy a Python environment

Last Updated:Jul 15, 2026

Install Python on an ECS instance with a package manager, from source, or with Pyenv for multi-version management.

Use a package manager to install Python

Package managers provide a quick installation method, but may offer outdated Python versions.

Alibaba Cloud Linux and CentOS

  1. Update the system packages.

    sudo yum update -y
  2. List available Python packages.

    In this example, the package manager provides Python 3.8 and Python 3.11.

    [root@i-xxx ~]# dnf list available | grep '^python3\([0-9]\)\?\(\.[0-9]\+\)\?\.x86_64*'
    python3.11.x86_64                    3.11.10-1.0.1.al8                          alinux3-updates
    python38.x86_64                      3.8.17-2.0.1.module+al8.6.0+10712+26c4c595 alinux3-module
  3. Select and install a Python version. This example uses Python 3.8. If no available version fits your needs, manually install Python.

    • x86 architecture

      sudo yum install python38.x86_64 -y
    • Arm architecture

      sudo yum install python38.aarch64 -y
  4. Run python3.8 -V to verify the installation.

    [root@iZ2xxxqkZ ~]# python3.8 -V
    Python 3.8.17

Ubuntu

  1. Update the system packages.

    sudo apt update
  2. List all available Python packages.

    In this example, the package manager provides Python 3.8 and Python 3.9.

    root@ixxxZ:~# apt-cache search python | grep '^python3\.[0-9]\+ '
    python3.8 - Interactive high-level object-oriented language (version 3.8)
    python3.9 - Interactive high-level object-oriented language (version 3.9)
  3. Select and install a Python version. This example uses Python 3.8. If no available version fits your needs, manually install Python.

    sudo apt install -y python3.8
  4. Run python3.8 -V to verify the installation.

    root@ixxx:~# python3.8 -V
    Python 3.8.10

Manually install Python

Use this method to install a specific Python version or apply custom build settings.

Alibaba Cloud Linux and CentOS

  1. Go to the Python website. In the top navigation bar, choose Downloads > Source code.

  2. Select a Python version, copy the download link, and download and extract the package. This example uses Python 3.8.10.

    # Replace https://www.python.org/ftp/python/3.8.10/Python-3.8.10.tgz with the actual URL.
    wget https://www.python.org/ftp/python/3.8.10/Python-3.8.10.tgz
    tar xzf Python-3.8.10.tgz
    cd Python-3.8.10
  3. Install the required dependencies.

    sudo yum groupinstall -y "Development Tools"
    sudo yum install -y python3-devel
  4. Compile and install the source code.

    ./configure --enable-optimizations
    make -j $(nproc)
    sudo make altinstall
  5. Verify the installation.

    [root@izxxx Z Python-3.8.10]#  python3.8 --version
    Python 3.8.10

Ubuntu

  1. Go to the Python website. In the top navigation bar, choose Downloads > Source code.

  2. Select a Python version, copy the download link, and download and extract the package. This example uses Python 3.8.10.

    wget https://www.python.org/ftp/python/3.8.10/Python-3.8.10.tgz
    tar -xzf Python-3.8.10.tgz
  3. Install the required dependencies.

    sudo apt update
    sudo apt install -y build-essential checkinstall libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libbz2-dev libffi-dev zlib1g-dev
  4. Compile and install the source code.

    cd Python-3.8.10
    ./configure --enable-optimizations
    make -j $(nproc)
    sudo make altinstall
  5. Run python3.8 -V to verify the installation.

    root@ixxxZ:~/Python-3.8.10# python3.8 -V
    Python 3.8.10

Windows

  1. Go to the Python website. In the top navigation bar, choose Downloads > Windows.

  2. Select a Python version. This example uses Python 3.8.10. Click Download Windows installer (64-bit) to download the installer.

  3. Double-click the installer to start the installation. In this example, the file is python-3.12.3-amd64.exe.

  4. Check Install launcher for all users (recommended) and Add Python 3.8 to PATH, then click Customize installation.

  5. On the Optional Features page, keep all optional features selected (Documentation, pip, tcl/tk and IDLE, Python test suite, py launcher), and click Next.

  6. On the Advanced Options page, check Add Python to environment variables, set the installation path to C:\Python38, and click Install.

  7. Open the Command Prompt, enter python, and press Enter. If the following output appears, Python is installed.

    C:\Users\Administrator>python
    Python 3.8.10 (tags/v3.8.10:3d8993a, May  3 2021, 11:48:03) [MSC v.1928 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>>

Install Python with Pyenv

Pyenv lets you install and switch between multiple Python versions on the same machine.

Install Pyenv

Alibaba Cloud Linux and CentOS

  1. Install the compiler and build dependencies:

    sudo yum groupinstall -y "Development Tools"
    sudo yum install -y openssl-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel libffi-devel xz-devel
  2. Install Pyenv:

    git clone https://gitee.com/mirrors/pyenv.git ~/.pyenv
  3. Configure the environment variables.

    Note

    Environment variables set with the export command apply only to the current session. To make them permanent, add the export command to your shell startup file.

    export PATH="$HOME/.pyenv/bin:$PATH"
    eval "$(pyenv init --path)"
    eval "$(pyenv init -)"
  4. Apply the new environment variables:

    source ~/.bashrc
  5. Verify the Pyenv installation:

    pyenv --version

Ubuntu

  1. Install the compiler and build dependencies:

    sudo apt update
    sudo apt install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev
  2. Install Pyenv:

    git clone https://gitee.com/mirrors/pyenv.git ~/.pyenv
  3. Configure the environment variables.

    Note

    Environment variables set with the export command apply only to the current session. To make them permanent, add the export command to your shell startup file.

    echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
    echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
    echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n  eval "$(pyenv init -)"\nfi' >> ~/.bashrc
  4. Apply the new environment variables:

    exec $SHELL
  5. Verify the Pyenv installation:

    pyenv --version

Windows

  1. In the taskbar search box, search for Windows PowerShell and click Open.

  2. Install Chocolatey in the Windows PowerShell.

    Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
    
  3. Use Chocolatey to install pyenv-win.

    choco install pyenv-win
  4. Configure the environment variables.

    Add pyenv to the system PATH. Right-click This PC, choose Properties > Advanced system settings > Environment Variables, select the Path variable in System variables, and click Edit. Add %USERPROFILE%\.pyenv\pyenv-win\bin to the path list and click OK.

  5. Close and reopen Windows PowerShell.

  6. Verify the Pyenv installation:

    pyenv --version

Install Python

After you install Pyenv, use it to install and manage multiple Python versions.

  1. List available Python versions.

    pyenv install -l | grep -E '^[^a-zA-Z]+$'
  2. Install the required Python versions. This example installs Python 3.8.10 and Python 3.12.1.

    Note

    By default, pyenv compiles with a single thread. To speed up the build, set export MAKE_OPTS="-j$(nproc)".

    pyenv install 3.8.10
    pyenv install 3.12.1
  3. View all installed Python versions.

    root@iZ****:~# pyenv versions
    * system (set by /root/.pyenv/version)
      3.8.10
      3.12.1
  4. Set the global default Python version.

    pyenv global 3.8.10
  5. Verify the current Python version.

    root@iZxxxZ:~# pyenv global 3.8.10
    root@iZxxxZ:~# pyenv version
    3.8.10 (set by /root/.pyenv/version)
  6. Set a project-specific Python version.

    pyenv local 3.12.1

References