Download and installation of Python under Linux system
1- Preparation before downloading and installing
In Linux, the pre-dependency environment needs to be installed in advance.
The command is as follows:
yum install wget zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make zlib zlib-devel libffi-devel -y
2- Download the Python program
2.1- Get the python program source code
- Enter the python official website ( click me to jump ), find the installation package of the linux system
- Right click on the Gzipped source tarball and select copy link address
2.2- Download the source code package in the linux terminal
wget https://www.python.org/ftp/python/3.11.1/Python-3.11.1.tgz
3- Install python
3.1- Unzip the source package
1. View the downloaded source package
[root@localhost ~]# ls -l
2. Decompress the compressed package
tar -xvf Python-3.11.1.tgz
3.2- Compile and install
- Enter the directory after decompression
[root@localhost ~]# cd Python-3.11.1/
- Configure the installation path after source code compilation
./configure --prefix=/usr/local/python3.11
- Start compiling and installing (about 10 minutes)
make && make install
-
After the compilation is complete, cd under the configured installation path, and view the contents of the folder.
The installation path I configured here: /usr/local/python3.11/
-
Check whether there is python3.11 in the bin directory, and the python installation has been completed at this time
4- Create a soft link
- At this point, the python environment has been installed successfully, but for the convenience of use, you need to delete the old version of the pyhton environment that comes with linux, and create a soft link for the new version of python
4.1- Delete the old version of Python environment
- The python2 version environment is installed by default in the linux system, and the directory is under /usr/bin/python/
[root@localhost bin]# /usr/bin/python
- After entering exit() and pressing Enter to exit the python environment, delete the python2 version
[root@localhost bin]# rm -f /usr/bin/python
4.2- Create soft link
- Link the newly installed python3.11 version to /usr/bin/python/
[root@localhost bin]# ln -s /usr/local/python3.11/bin/python3.11 /usr/bin/python
- Enter python to verify
5- Repair yum program
- The yum program in the linux system uses the python2 version by default. Now the latest version of python is replaced by the python2 version, so the relevant configuration of yum needs to be modified to ensure that the operation of the yum program will not be affected when the python installation is completed. The modification is as follows:
- Modify /usr/libexec/urlgrabber-ext-down, after modification: wq save and exit
[root@localhost bin]# vi /usr/libexec/urlgrabber-ext-down
- Modify the /usr/bin/yum file, after modification: wq save and exit
[root@localhost bin]# vi /usr/bin/yum