操作系统:CentOS Linux release 7.6.1810 Python:3.7.4
当前CentOS系统自带了python2.7.5,因为yum会用到python2,所以不能删除,此次安装了python3之后就保持两个版本长期共存吧。
本次安装采用的是下载python源码再编译的方式;
以root身份登录CentOS,以下操作都在默认的~目录下:
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
编译成功后提示如下信息,setuptools和pip都已经部署成功:
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
至此,安装完成,接下来简单验证一下
[root@python3 ~]# python3 --version
Python 3.7.4
[root@python3 ~]# pip3 --version
pip 19.1.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7)
[root@python3 ~]# python3
Python 3.7.4 (default, Jul 20 2019, 11:35:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("Hello world")
Hello world
按下Ctrl+d退出python3对话模式 2. 安装Flask:
pip3 install Flask
控制台输出以下信息,表示安装Flask成功:
[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
至此,python3、pip3都验证通过。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。