All Products
Search
Document Center

Alibaba Cloud SDK:Install Python

Last Updated:Dec 24, 2024

This topic describes how to install Python in different operating systems.

Install Python in Windows

  1. Go to the Python official website. 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 package to install Python. In this example, the downloaded installation package 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 the Enter key. If the output is similar to that in the following figure, Python is installed.

    image

Install Python in Linux

CentOS

  1. Go to the Python official website and download the required Python version. In this example, Python 3.11.10 is installed.

    wget https://www.python.org/ftp/python/3.11.10/Python-3.11.10.tgz
  2. Decompress the installation package.

    tar -xzvf Python-3.11.10.tgz
  3. Install the compilation environment that is required by the source code.

    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
  4. Compile and install Python. Go to the directory to which the installation package is decompressed and specify the installation directory of Python 3 as /usr/python.

    cd Python-3.11.10
    ./configure --prefix=/usr/python 
    make
    make install

    image

  5. Run the which python3 pip3 command to check whether symbolic links exist in the system. If symbolic links exist, delete the symbolic links.

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

    image

  6. Recreate and specify symbolic links.

    Note

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

    sudo ln -s /usr/python/bin/python3 /usr/bin/python3
    sudo ln -s /usr/python/bin/pip3 /usr/bin/pip3
  7. Check the installed Python version.

    python3 --version 

    image

  8. Check the installed pip version.

    pip3 -V

    image

Alibaba Cloud Linux

  1. Go to the Python official website and download the required Python version. In this example, Python 3.11.10 is installed.

    sudo curl -O https://www.python.org/ftp/python/3.11.10/Python-3.11.10.tgz
  2. Decompress the installation package.

    sudo tar xzf Python-3.11.10.tgz
  3. To compile Python and its extensions, some development tools and libraries are required. Run the following commands to install the required dependencies:

    sudo yum groupinstall "Development Tools" -y
    sudo yum install openssl-devel bzip2-devel libffi-devel -y
  4. Compile and install Python.

    cd Python-3.11.10
    sudo ./configure --enable-optimizations
    sudo make altinstall

    image

    Note

    The make altinstall command is used to prevent the default Python version from being overwritten.

  5. Run the which python3 pip3 command to check whether symbolic links exist in the system. If symbolic links exist, delete the symbolic links.

    sudo rm /usr/bin/python3
    sudo rm /usr/bin/pip3

    image

  6. Recreate and specify symbolic links.

    Note

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

    sudo ln -s /usr/local/bin/python3.11 /usr/bin/python3
    sudo ln -s /usr/local/bin/pip3.11 /usr/bin/pip3
  7. Check the installed Python version.

    python3 --version 

    image

  8. Check the installed pip version.

    pip3 -V

    image

Ubuntu

  1. Go to the Python official website and select the required Python version.

  2. Update the software package index.

    sudo apt update

    image

  3. Download the required Python version. In this example, Python 3.11.10 is downloaded.

    wget https://www.python.org/ftp/python/3.11.10/Python-3.11.10.tgz
  4. Decompress the downloaded source code package.

    tar -xzf Python-3.11.10.tgz
  5. Install the required dependencies.

    sudo apt install -y build-essential checkinstall
    sudo apt install -y libreadline-gplv2-dev libncursesw5-dev libssl-dev \
    libsqlite3-dev tk-dev libgdbm-dev libbz2-dev libffi-dev zlib1g-dev

    image

  6. Go to the directory to which the installation package is decompressed, and configure, compile, and then install Python.

    cd Python-3.11.10
    ./configure --enable-optimizations
    make -j $(nproc)
    sudo make altinstall
  7. Run the which python3 pip3 command to check whether symbolic links exist in the system. If symbolic links exist, delete the symbolic links.

    sudo rm /usr/bin/python3
    sudo rm /usr/bin/pip3

    image

  8. Recreate and specify symbolic links.

    Note

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

    sudo ln -s /usr/local/bin/python3.11 /usr/bin/python3
    sudo ln -s /usr/local/bin/pip3.11 /usr/bin/pip3
  9. Check the installed Python and pip versions.

    python3 --version 
    pip3 -V

    image

FAQ

  • What do I do if the "The installer was interrupted before Python could be installed" error message is returned in Windows?

    This error message is returned because the Windows installer of Python is interrupted. To resolve this issue, you can delete the downloaded installer, download an installation package again from the Python official website, and then install Python.

  • What do I do if the "-bash: python3: command not found" error message is returned in Linux?

    1. Check whether Python 3 is installed. You can run the which python3 command to check the directory in which Python 3 is installed. If a directory such as /usr/bin/python3 is returned, Python 3 is installed.

    2. If you have installed Python 3, this error message may be returned because symbolic links are not properly configured. Check whether symbolic links exist in the system. If necessary, delete the symbolic links and configure symbolic links again.

      sudo which python3 pip3
      rm -rf /usr/bin/python3 /usr/bin/pip3
      
      # Specify the /usr/python/bin/python3 symbolic link as the installation directory of Python 3.
      sudo ln -s /usr/python/bin/python3 /usr/bin/python3
      sudo ln -s /usr/python/bin/pip3 /usr/bin/pip3
  • What do I do if the "Permission denied" error message is returned in Linux?

    This error message is returned because you do not have sufficient permissions to perform an operation. In most cases, you can run the sudo command to escalate your permissions. In this case, the commands that require administrator permissions can be run.

    Important

    Running the sudo command is not always a secure solution. Before you run the sudo command, we recommend that you identify the root cause of insufficient permissions. If you need to escalate your permissions, make sure that you understand the potential security risks and run the sudo command only when necessary.