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)
Operating system: CentOS Linux release 7.6.1810
Python:3.7.4
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;
Log in to CentOS as root, and the following operations are in the default ~ directory:
yum update -y
yum -y install \
zlib-devel \
bzip2-devel \
openssl-devel \
ncurses-devel \
sqlite-devel \
readline-devel \
tk-devel \
libffi-devel \
wget \
gcc \
make
wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
tar -zxvf Python-3.7.4.tgz
cd Python-3.7.4&&./configure prefix=/usr/local/python3
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
ln -s /usr/local/python3/bin/python3.7/usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
pip3 install --upgrade pip
At this point, the installation is complete, and then simply verify
[ 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
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)
python3 hello.py
So far, python3 and pip3 have all been verified.
Recommended Posts