How to install python3.6 under CentOS7

Although Ubuntu18.04LTS has built-in support for python3.6, but sometimes CentOS7 is still used, let's summarize how to install python3.6 under CentOS7

1. Preparation before installing python

  1. In order to reduce errors in the future, first download the required software below

    yum install zlib* openssl*
    yum install gcc
    yum install sqlite-devel
  2. Create a python3 folder and enter the folder

    mkdir /usr/local/python3
    cd /usr/local/python3
  3. Download the source code of python3

    wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
  4. Unzip the python3 source code

    tar -zxvf Python-3.6.5.tgz

2. Compile python3

  1. Go to the python3 source folder and precompile

    cd Python-3.6.5
    ./configure --prefix=/usr/local/python3/python3 --enable-optimizations
  2. Compile (takes a long time)

    make
  3. Installation (also takes longer)

    make install

3. Configure system environment variables

Open configuration file

vi ~/.bashrc

Add a line after the end PATH=$PATH:/usr/local/python3/python3/bin
and execute after saving and exiting

source ~/.bashrc

This is done!

python3Start using python3 by typing in the command line

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325123349&siteId=291194637