The CentOS7 environment builds python3 and the way it coexists with python2 implementations

  • 2020-10-23 21:18:31
  • OfStack

This article gives an example of how CentOS7 builds python3 and coexists with python2 implementations. To share for your reference, the details are as follows:

Notes:

1. Non-root account plus sudo

2. centos7 comes with Python 2.7.5, which cannot be uninstalled. Many system-level software rely on it

Install dependencies


# yum -y groupinstall "Development tools"
# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

Download python3 and mine is ES20en-3.4.2.tgz


# wget https://www.python.org/ftp/python/3.4.2/Python-3.4.2.tgz
# mkdir /usr/local/python3
# tar -zxvf Python-3.4.2.tgz
# cd Python-3.4.2
# ./configure --prefix=/usr/local/python3
# make && make install
# ln -s /usr/local/python3/bin/python3 /usr/bin/python3

test

Check the version


# python3
Python 3.4.2 (default, Jul 19 2016, 03:47:32)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

The test code

Create a new python script in the current directory, hello.py

Content:


#!/usr/bin/python3
#  The first 1 A comment 
print ("Hello, Python3!")
 perform 
# python3 hello.py
Hello, Python3!

Hopefully this article has helped you with CentOS server maintenance.


Related articles: