This topic describes how to install Python.
Install Python on Windows
Visit the official website of Python. In the top navigation bar, choose Downloads > Windows.
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.
Double-click the downloaded installation file to install Python. In this example, the downloaded installation file is python-3.12.3-amd64.exe.
Select Add python.exe to PATH and click Customize installation.
Click Next.
Modify the installation path and click Install.
After the installation is complete, press
Win+R
to open the Run dialog box. Entercmd
in the field and click OK to open Command Prompt.Enter
python
and press Enter. If the output is similar to that in the following figure, Python is installed.
Install Python on Linux
Visit the official website of Python. In the top navigation bar, choose Downloads > Source code.
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.
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.
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
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
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
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
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:
NoteWhen 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.
sudo ln -s /usr/local/python3/bin/python3.12 /usr/bin/python3 sudo ln -s /usr/local/python3/bin/pip3.12 /usr/bin/pip3
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