All Products
Search
Document Center

Alibaba Cloud SDK:Install Python

最終更新日:Jun 11, 2024

This topic describes how to install Python.

Install Python on Windows

  1. Visit the official website of Python. In the top navigation bar, choose Downloads > Windows.

    image

  2. In the Stable Releases section, select a stable version and click a download link. In this example, Python 3.12.3 is selected and Windows installer (64-bit) is downloaded.

    image

  3. Double-click the downloaded installation file to install Python. In this example, the downloaded installation file is python-3.12.3-amd64.exe.

  4. Select Add python.exe to PATH and click Customize installation.

    image

  5. Click Next.

    image

  6. Modify the installation path and click Install.

    image

  7. After the installation is complete, press Win+R to open the Run dialog box. Enter cmd in the field and click OK to open Command Prompt.

  8. Enter python and press Enter. If the output is similar to that in the following figure, Python is installed.

    image

Install Python on Linux

  1. Visit the official website of Python. In the top navigation bar, choose Downloads > Source code.

    image

  2. In the Stable Releases section, select a stable version and click a download link. In this example, Python 3.12.3 is selected and Gzipped source tarball is downloaded.

    image

  3. Upload the installation file to a Linux server. In this example, the installation file Python-3.12.3.tgz is uploaded to an Elastic Compute Service (ECS) instance. For more information, see Upload a file from on-premises to an ECS instance.

  4. Go to the directory to which the installation file is uploaded and decompress the installation file. In this example, the installation file is uploaded to the usr directory.

    cd /usr
    tar -xzvf Python-3.12.3.tgz
    

    image

  5. Install the Python environment dependencies.

    sudo yum -y install gcc
    sudo yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel libpcap-devel xz-devel libffi-devel
    
  6. Compile Python 3 and install it in the /usr/local/python3 directory.

    mkdir /usr/local/python3
    cd Python-3.12.3
    ./configure --prefix=/usr/local/python3
    make && sudo make altinstall
    
  7. Run the which python3 pip3 command to check whether symbolic links exist in the system. If yes, delete the symbolic links.

    rm -rf /usr/bin/python3 /usr/bin/pip3
    

    image

  8. Re-create symbolic links. Obtain the installation directory of Python from Step 6, go to the bin directory, and find pip3.12 and python3.12. Run the following commands to create new symbolic links:

    Note

    When a user access a symbolic link, the user actually accesses the file to which the symbolic link points. For example, when you use python3, you actually use the Python 3.12 interpreter.

    image

    sudo ln -s /usr/local/python3/bin/python3.12 /usr/bin/python3
    sudo ln -s /usr/local/python3/bin/pip3.12 /usr/bin/pip3
    
  9. Run the following commands to check whether Python is installed. If the output is similar to that in the following figure, Python is installed.

    python3 -V
    pip3 -V
    

    image

FAQ

  • How do I fix the -bash: python3: command not found error that is returned when I run the command to view the Python version?

    • If you have installed Python, this error may be returned because the symbolic links are incorrectly configured.

      Resolve this issue by referring to Step 7 and Step 8.