Ubuntu18.04系统如何安装sanic

[复制链接] |主动推送
查看207 | 回复0 | 2024-9-12 00:47:07 | 显示全部楼层 |阅读模式
Sanic 是一个类Flask 的基于Python3.5 的web框架,它编写的代码速度特别快。那么在ubuntu18.04中如何安装sanic呢?本文给出详细说明。
1.首先确认安装了python3
000444hs11mptgmtkmt000.jpg
说明:一般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 sanic
5.创建一个sanic程序
vi hello.py
在其中写入
from sanic import Sanic
from sanic.response import text
app = Sanic(__name__)
@app.route('/')
async def hello_world(request):
return text('
hello,world
')
app.run(host="0.0.0.0", port=8000, debug=True)
保存退出
6.运行hello.py
python3 hello.py
000445po7pueypupv2pbko.jpg

7.测试
在浏览器打开主机IP:8000
000445y578o247547zx7os.jpg
安装成功
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则