Ubuntu18.04系统如何安装flask
Ubuntu18.04系统如何安装flask
Flask是一个使用Python编写的轻量级Web应用框架。基于Werkzeug WSGI工具箱和Jinja2 模板引擎。那么在ubuntu18.04中如何安装flask呢?本文给出详细说明。
1.首先确认安装了python3

说明:一般linux系统默认都有安装python环境,包括python2和python3,在命令行中python默认指的是python2。python2已经接近淘汰,但由于linux系统环境中还有大量基于python2的软件,因此在linux系统中还保留着python2。目前推荐使用python3。
2.更新软件列表
sudo apt-get update
3.安装python3-pip
sudo apt-get install python3-pip
4.安装flask
sudo pip3 install flask
5.创建一个最小的flask程序
vi hello.py
在其中写入
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'hello,world'

保存退出
6.设置FLASK_APP 环境变量,并设置服务器允许外部访问
export FLASK_APP=hello.py
flask run --host=0.0.0.0

7.测试
在浏览器打开主机IP:5000

安装成功