Download and installation of Python under Linux system

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

insert image description here

2- Download the Python program

2.1- Get the python program source code

  1. Enter the python official website ( click me to jump ), find the installation package of the linux system
    insert image description here
    insert image description here
    insert image description here
  2. Right click on the Gzipped source tarball and select copy link address
    insert image description here

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

insert image description here

3- Install python

3.1- Unzip the source package

1. View the downloaded source package

[root@localhost ~]# ls -l

insert image description here
2. Decompress the compressed package

tar -xvf Python-3.11.1.tgz

insert image description here

3.2- Compile and install

  1. Enter the directory after decompression

[root@localhost ~]# cd Python-3.11.1/

insert image description here

  1. Configure the installation path after source code compilation

./configure --prefix=/usr/local/python3.11

insert image description here

  1. Start compiling and installing (about 10 minutes)

make && make install

insert image description here

  1. 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/

    insert image description here

  2. Check whether there is python3.11 in the bin directory, and the python installation has been completed at this time

insert image description here

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

  1. 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

insert image description here

  1. 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

  1. 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

  1. Enter python to verify
    insert image description here

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:
  1. Modify /usr/libexec/urlgrabber-ext-down, after modification: wq save and exit

[root@localhost bin]# vi /usr/libexec/urlgrabber-ext-down

insert image description here

  1. Modify the /usr/bin/yum file, after modification: wq save and exit

[root@localhost bin]# vi /usr/bin/yum

insert image description here

You're done installing the Python environment on the Linux system, let's go!

Guess you like

Origin blog.csdn.net/qq_33999977/article/details/128222675