Updated on 2025-08-06 GMT+08:00

Setting Up a Python Environment

Overview

Python is a widely used interpretive, high-level, and general programming language. Python supports multiple programming paradigms, including structured, procedural, reflective object-oriented, and functional programming. It employs a dynamic type system and automatic garbage collection to manage memory efficiently. It has a large and comprehensive standard library. Its language structure and object-oriented method are designed to help programmers write clear, logical code for small and large projects.

This section describes how to set up a Python environment on an ECS.

Prerequisites

  1. The ECS has an EIP bound.
  2. The rule listed in the following table has been added to the security group which the target ECS belongs to. For details, see Adding a Security Group Rule.
    Table 1 Security group rule

    Direction

    Priority

    Action

    Type

    Protocol & Port

    Source

    Inbound

    1

    Allow

    IPv4

    TCP: 80

    0.0.0.0/0

Deploying Python

Perform the corresponding operations based on the operating system.

CentOS 8.0

  1. Visit the Python official website, hover the cursor over Downloads, and click Source code.

  2. Select the Python version to be installed, copy the download link, and run the following commands to download and decompress the package. In this example, Python 3.9.22 is installed.
    wget https://www.python.org/ftp/python/3.9.22/Python-3.9.22.tgz
    tar xzf Python-3.9.22.tgz
    cd Python-3.9.22
  3. Run the following commands to install the dependencies:
    sudo yum groupinstall -y "Development Tools"
    sudo yum install -y python3-devel
  4. Run the following commands to compile and install the software:
    ./configure --enable-optimizations
    make -j $(nproc)
    sudo make altinstall
  5. Run the following command to view the installation result:
    python3.9 --version

Ubuntu 22.04

  1. Visit the Python official website, hover the cursor over Downloads, and click Source code.

  2. Select the Python version to be installed, copy the download link, and run the following commands to download and decompress the package. In this example, Python 3.9.22 is installed.
    wget https://www.python.org/ftp/python/3.9.22/Python-3.9.22.tgz
    tar -xzf Python-3.9.22.tgz
  3. Run the following commands to install the 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. Run the following commands to compile and install the software:
    cd Python-3.9.22
    ./configure --enable-optimizations
    make -j $(nproc)
    sudo make altinstall
  5. Run the following command to view the installation result:
    python3.9 --version

Windows 2022

  1. Visit the Python official website, hover the cursor over Downloads, and click Windows.

  2. Select the Python version to be installed, for example, Python 3.13.2. Click Download Windows installer (64-bit) to download the installation file.

  3. Double-click the downloaded installation file python-3.13.2-amd64.exe to start the installation.
  4. Select Customize installation and Add python.exe to PATH.

  5. Click Next.

  6. Change the installation path and click Install.

  7. After the installation is complete, open the CLI, enter python, and press Enter. If the following information is displayed, Python has been installed.