Coexistence of python2 and python3 under centos7 system

Coexistence of python2 and python3 under centos7 system

The first step is to check the version number and installation path of Python;

From the above view, we can see that python points to python2 by default, so we don’t change it here and just keep the current state.

Note: (Because there are still many system updates that require the use of pyhton2, such as: Centos7 yum installation and update. Frameworks such as Django now use python3 by default)

The second step is to install the related dependency libraries of python3.

1. Install dependencies that may be used by python3.7 yum -y install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel wget
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc
yum -y install libffi-devel 

2. Download Python 3
cd /tmp/
wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz

3. Unzip the downloaded compressed package tar -zxvf Python-3.7.4.tgz

4. Configure and compile mkdir /usr/local/python3
cd Python-3.7.4/ 
 ./configure --enable-shared --prefix=/usr/local/python3 --enable-optimizations
make
make install

Step 4: After the installation is complete, create a soft link

Later use is to directly enter python and run python2. Enter python3 to run pyhton3.

cd /usr/local/python3/bin/
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

pip3 install --upgrade pip

This step may result in the following error:

Error message:

python3: error while loading shared libraries: libpython3.7m.so.1.0: cannot open shared object file: No such file or directory

Solution: (Enter the installation directory and copy the file)

cd /tmp/Python-3.7.4/
cp libpython3.7m.so.1.0 /usr/local/lib64
cp libpython3.7m.so.1.0 /usr/lib/
cp libpython3.7m.so.1.0 /usr/lib64/ 

Step 5. Complete all installations and create a Python virtual environment for the next update

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • Python2 and Python3 implement the method of adding Chinese characters to pictures
  • Implementation of replacing cmp function in python2 in python3
  • Summary of examples of the differences between Python 2 and Python 3
  • Coexistence and switching between Python2 and Python3
  • The differences between Python2 and Python3

<<:  Practical Optimization of MySQL Paging Limit

>>:  MySQL scheduled task example tutorial

Recommend

Detailed explanation of Angular structural directive modules and styles

Table of contents 1. Structural instructions Modu...

Detailed introduction to JS basic concepts

Table of contents 1. Characteristics of JS 1.1 Mu...

Use of Docker UI, a Docker visualization management tool

1. Introduction to DockerUI DockerUI is based on ...

IE6 implements min-width

First of all, we know that this effect should be ...

Tutorial on installing MySQL on Alibaba Cloud Centos 7.5

It seems that the mysql-sever file for installing...

Vue implements Tab tab switching

This article example shares the specific code of ...

Mini Program implements custom multi-level single-select and multiple-select

This article shares the specific code for impleme...

How to solve the timeout during pip operation in Linux

How to solve the timeout problem when pip is used...

MySQL implements a solution similar to Oracle sequence

MySQL implements Oracle-like sequences Oracle gen...

Detailed explanation of explain type in MySQL

Introduction: In many cases, many people think th...

Introduction to Sublime Text 2, a web front-end tool

Sublime Text 2 is a lightweight, simple, efficien...

Summary of MySql index, lock, and transaction knowledge points

This article summarizes the knowledge points of M...

Four ways to compare JavaScript objects

Table of contents Preface Reference Comparison Ma...

Summary of some small issues about MySQL auto-increment ID

The following questions are all based on the Inno...