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

Semantics, writing, and best practices of link A

The semantics, writing style, and best practices ...

td width problem when td cells are merged

In the following example, when the width of the td...

CSS achieves highly adaptive full screen

When writing my own demo, I want to use display:f...

Detailed explanation of Linux copy and paste in VMware virtual machine

1. Linux under VMware Workstation: 1. Update sour...

How to analyze MySQL query performance

Table of contents Slow query basics: optimizing d...

JavaScript Canvas draws dynamic wireframe effect

This article shares the specific code of JavaScri...

Sharing of experience on repairing MySQL innodb exceptions

A set of MySQL libraries for testing. The previou...

Detailed installation and configuration tutorial of PostgreSQL 11 under CentOS7

1. Official website address The official website ...

Understanding of CSS selector weight (personal test)

Copy code The code is as follows: <style type=...

How to use ES6 class inheritance to achieve a gorgeous ball effect

Table of contents introduce Implementation steps ...

How to enable TLS and CA authentication in Docker

Table of contents 1. Generate a certificate 2. En...

Summary of changes in the use of axios in vue3 study notes

Table of contents 1. Basic use of axio 2. How to ...

Detailed explanation of overflow-scrolling to solve scrolling lag problem

Preface If you use the overflow: scroll attribute...

Vue routing lazy loading details

Table of contents 1. What is lazy loading of rout...