python install linux

        In the previous article, we demonstrated the installation process of Python in the windows environment. This article introduces how to install python in the Linux environment.

        Server environment: Linux CentOS 7.4

        Python version: 3.10.6

1. Install Python dependencies

        Here we install directly through yum, enter the following command to install.

yum install zlib-devel bzip2-devel opssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc libffi-devel

2. Install Python

1. Find the Python source code installation package for the Linux environment on the Python official website, download address: Python installation package download address , copy the download link.

Enter the corresponding python version.

 Right click > copy link address.

2. Under the Linux server, download the installation package through wget. The path for downloading the installation package here is /usr/local/.

wget https://www.python.org/ftp/python/3.10.6/Python-3.10.6.tgz

 3. After the download is complete, tar decompresses the installation package.

tar -xvf Python-3.10.6.tgz

4. Enter the decompressed file for pre-configuration, the configuration path is /usr/local/python/.

cd Python-3.10.6

./configure --prefix=/usr/local/python

5. Compile & install

make & make install

3. Create a soft connection

1. Modify the default Python version of linux

The Linux system will install a Python by default. Enter python on the command line to see the default version number.

 First remove the default python installer.

rm -f /usr/bin/python

2. Create a soft link to the latest python3.10.6.

ln -s /usr/local/python/bin/python3.10 /usr/bin/python

After creating the soft link, enter python, and you can see that it is the latest version we have installed.

 3. Modify yum to rely on the default python version

After creating a soft connection, the normal use of the yum program will be destroyed. The code of yum is only compatible with python2, so the interpreter of python2 should be used, so python should be changed to python2

vi /usr/libexec/urlgrabber-ext-down

Change the first line of python to python2 

vi /usr/bin/yum

 Also change the first line of python to python2

4. Modify the python version of the firewall

 vi /usr/bin/firewall-cmd

Change the first line of python to python2

vi /usr/sbin/firewalld 

         After modifying these files, the installation of python has been completed, and the python of yum dependency and firewall has also been modified to the latest version of python.

5. Create a soft link to pip3

        pip is a management tool for Python packages.

ln -s /usr/local/python/bin/pip3.10 /usr/bin/pip3

        Use the pip3 command when installing third-party packages

Guess you like

Origin blog.csdn.net/weixin_64940494/article/details/126266917