CentOS7 install python3 and pip3

Copyright notice: Attribution, allowing others to create based on this article, and this article must be distributed based on the same license agreement as the original license agreement (Creative Commons)

Environmental information###

Operating system: CentOS Linux release 7.6.1810
Python:3.7.4

Status description###

The current CentOS system comes with python2.7.5, because yum will use python2, so it cannot be deleted. After installing python3 this time, keep the two versions coexisting for a long time.

This installation uses the method of downloading the python source code and compiling;

Steps###

Log in to CentOS as root, and the following operations are in the default ~ directory:

  1. Yum update:
yum update -y
  1. Install the necessary software:
yum -y install \
zlib-devel \
bzip2-devel \
openssl-devel \
ncurses-devel \
sqlite-devel \
readline-devel \
tk-devel \
libffi-devel \
wget \
gcc \
make
  1. Download the python3.7.4 source code:
wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
  1. Unzip:
tar -zxvf Python-3.7.4.tgz
  1. Enter the decompressed directory and perform the configure operation before compilation:
cd Python-3.7.4&&./configure prefix=/usr/local/python3
  1. To compile the source code, execute the following command in the Python-3.7.4 directory:
make && make install

After successful compilation, the following message is displayed, and both setuptools and pip have been deployed successfully:

Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-19.0.3 setuptools-40.8.0
  1. Create a link to python3:
ln -s /usr/local/python3/bin/python3.7/usr/bin/python3
  1. Create a link to pip3:
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
  1. pip3 upgrade
pip3 install --upgrade pip

At this point, the installation is complete, and then simply verify

verification###

  1. The simple operation is as follows, it can be seen that python3 is installed successfully:
[ root@python3 ~]# python3 --version
Python 3.7.4[root@python3 ~]# pip3 --version
pip 19.1.1from/usr/local/python3/lib/python3.7/site-packages/pip(python 3.7)[root@python3 ~]# python3
Python 3.7.4(default, Jul 202019,11:35:19)[GCC 4.8.520150623(Red Hat 4.8.5-36)] on linux
Type "help","copyright","credits" or "license"for more information.>>>print("Hello world")
Hello world

Press Ctrl+d to exit python3 dialogue mode
2. Install Flask:

pip3 install Flask

The console outputs the following information, indicating that Flask is installed successfully:

[ root@python3 ~]# pip3 install Flask
Collecting Flask
 Downloading https://files.pythonhosted.org/packages/9b/93/628509b8d5dc749656a9641f4caf13540e2cdec85276964ff8f43bbb1d3b/Flask-1.1.1-py2.py3-none-any.whl(94kB)|████████████████████████████████| 102kB 431kB/s 
Collecting itsdangerous>=0.24(from Flask)
 Downloading https://files.pythonhosted.org/packages/76/ae/44b03b253d6fade317f32c24d100b3b35c2239807046a4c953c7b89fa49e/itsdangerous-1.1.0-py2.py3-none-any.whl
Collecting click>=5.1(from Flask)
 Downloading https://files.pythonhosted.org/packages/fa/37/45185cb5abbc30d7257104c434fe0b07e5a195a6847506c074527aa599ec/Click-7.0-py2.py3-none-any.whl(81kB)|████████████████████████████████| 81kB 1.3MB/s 
Collecting Jinja2>=2.10.1(from Flask)
 Downloading https://files.pythonhosted.org/packages/1d/e7/fd8b501e7a6dfe492a433deb7b9d833d39ca74916fa8bc63dd1a4947a671/Jinja2-2.10.1-py2.py3-none-any.whl(124kB)|████████████████████████████████| 133kB 1.8MB/s 
Collecting Werkzeug>=0.15(from Flask)
 Downloading https://files.pythonhosted.org/packages/d1/ab/d3bed6b92042622d24decc7aadc8877badf18aeca1571045840ad4956d3f/Werkzeug-0.15.5-py2.py3-none-any.whl(328kB)|████████████████████████████████| 337kB 3.4MB/s 
Collecting MarkupSafe>=0.23(from Jinja2>=2.10.1->Flask)
 Downloading https://files.pythonhosted.org/packages/98/7b/ff284bd8c80654e471b769062a9b43cc5d03e7a615048d96f4619df8d420/MarkupSafe-1.1.1-cp37-cp37m-manylinux1_x86_64.whl
Installing collected packages: itsdangerous, click, MarkupSafe, Jinja2, Werkzeug, Flask
Successfully installed Flask-1.1.1 Jinja2-2.10.1 MarkupSafe-1.1.1 Werkzeug-0.15.5 click-7.0 itsdangerous-1.1.0
  1. Create a file named hello.py with the following content:
from flask import Flask

app =Flask(__name__)

@ app.route('/')
def hello():return'Hello flask'if __name__ =='__main__':
  app.run(host='0.0.0.0',port=5000,debug=True)
  1. Run the script:
python3 hello.py
  1. The IP address of the current CentOS computer is 192.168.121.134. When you visit: in the browser, the response is shown in the following figure:

So far, python3 and pip3 have all been verified.

Recommended Posts

CentOS7 install python3 and pip3
CentOS quickly install Python3 and pip3
centos7 install python3 and ipython
CentOS 6.9 compile and install python
Centos6 install python3 pip3 ipython3
CentOS 6 compile and install python 3
Centos6 install Python2.7.13
Centos7 install Python 3.6.
CentOS install Python 3.6
Centos7 install Python2.7
Centos install Python3
CentOS6.8 install python2.7
Install Python3 and ansible under CentOS8
Install Python3 and Py under CentOS7
Install centos7 and connect
Know Linux and install CentOS
CentOs7.3 compile and install Nginx 1.9.9
CentOS 7 install Mono and MonoDevelop
ubuntu18.04 compile and install python3.8
CentOS6.5 install Java 8 and Tomcat8
Centos compile and install Git
Centos 6.10 reinstall python and yum
Centos6.5 install and configure mongodb
CentOS7 install OracleJDK and JRE
CentOS6.5 install Java 8 and Tomcat8
CentOS6 install and crack Jira 7
CentOS6.5 install Java 8 and Tomcat8
Centos7 compile and install ntp-4.2.8p11
CentOS6 install and crack confluence
CentOS6 install and crack Jira 7
CentOS + Python3.6+
1.5 Install Centos7
Centos 7.5 python3.6
Centos 7 install jdk and package service service
CentOS7 yum install and start mysql
Install and configure keepalived under CentOS 5.9
CentOS Yum compile and install MySQL 5.6
Compile and install LAMP under Centos 5.2
CentOS 8 install Git and basic configuration
CentOS 6.x compile and install Nginx
CentOS7.3 install iptables and detailed use
How to install Python 3.8 on CentOS 8
CentOS7 yum install and start mysql
CentOS 8 - install and configure NFS service
Centos7 and centos8 install mysql5.6 5.7 8.0 so simple
Centos7 uninstall openJdk, and install JDK1.8
How to install Python on CentOS 8
Install and use docker under CentOS 6.8
CentOS7 install and use SQL Server
Configure python3 environment on centos7 and
CentOS Minimal install and configure TIPS
Install and configure FreeIPA in Centos7
Linux CentOS6 compile and install Pyt
virtualBox install centos, and build tomcat
Install Mono 3.2 and Jexus 5.4 under CentOS 6.3
Compile and install libmodbus library under CentOS7
Centos7.3 install nginx
CentOS install Redmine
CentOS7 install MySQL
Centos7 install protobuf
python Douban replaces pip to install python module