ubuntu16.04系统安装flask步骤

1.更新源

刚装的系统默认的是美国的源,为了避免后续下载缓慢等问题,第一步先更新国内的源

本人装的是阿里的源

//在修改之前先备份sources.list的文件进行备份
进入到文件夹下
1、cd /etc/apt
sudo cp sources.list sourecs_copy.list
//修改sources.list文件
2、sudo gedit sources.list

3、
//以下的是阿里的源,把它复制到sources.list中保存即可
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties...
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties 
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse

//更新源
sudo apt-get update
//更新软件
sudo apt-get upgrade

2.搭建virtualenv环境

//第一步:安装easy_install工具
sudo apt-get install python-setuptools python-dev build-essential
//第二步:easy_install安装完成以后,安装virtualenv
sudo easy_install virtualenv
//第三步:安装好virtualenv后就安装pip
sudo easy_install pip
//第四步:最后就是安装Flask
sudo pip install Flask

3、创建hello.py文件,并运行

//创建my_project文件夹
sudo mkdir my_project
//进入该文件夹下创建hello.py文件
sudo touch hello.py
//进入编辑该文件
sudo gedit hello.py
//在文件下写入下面代码
from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "hello world"
    
if __name__ == "__main__":
    app.run()
//然后运行hello.py
python hello.py
//在浏览器中输入
127.0.0.1:500
浏览器会输出hello world

ubuntu16.04系统安装flask步骤_第1张图片


注意:有些新装的系统可能没有gedit命令需要自己安装

慈溪蹩脚程序员找了一个方法,自己运行无障碍

ubuntu安装gedit插件
1.sudo apt-get update
2.sudo apt-get install gedit-plugins

小源也是CSDN新手,大家觉得有帮助就点个赞,让我有点动力,成就感。三口三扣

你可能感兴趣的:(树莓派)