厦门服务器租用>动态拨号VPS>Ubuntu18.04系统如何安装Pyramid

Ubuntu18.04系统如何安装Pyramid

发布时间:2023/2/7 13:26:05

Ubuntu18.04系统如何安装Pyramid

Pyramid 是一个小型、快速、实际的python web框架。那么在ubuntu18.04中如何安装Pyramid呢?本文给出详细说明。

1.首先确认安装了python3

Ubuntu18.04系统如何安装Pyramid-1381

说明:一般linux系统默认都有安装python环境,包括python2和python3,在命令行中python默认指的是python2。python2已经接近淘汰,但由于linux系统环境中还有大量基于python2的软件,因此在linux系统中还保留着python2。目前推荐使用python3。

2.更新软件列表

sudo apt-get update

Ubuntu18.04系统如何安装Pyramid-1382

3.安装python3-pip

sudo apt install python3-pip

Ubuntu18.04系统如何安装Pyramid-1383

4.安装requests库

sudo pip3 install Pyramid

Ubuntu18.04系统如何安装Pyramid-1384

5.编写测试程序

vi hello.py

写入以下内容

from wsgiref.simple_server import make_server

from pyramid.config import Configurator

from pyramid.response import Response

def hello_world(request):

return Response('hello world')

if __name__ == '__main__':

with Configurator() as config:

config.add_route('hello','/')

config.add_view(hello_world,route_name='hello')

app = config.make_wsgi_app()

server = make_server('0.0.0.0',6543,app)

server.serve_forever()

保存退出

6.测试

python3 hello.py

在浏览器访问ip:6543

Ubuntu18.04系统如何安装Pyramid-1385

在线客服
微信公众号
免费拨打400-1886560
免费拨打0592-5580190 免费拨打 400-1886560 或 0592-5580190
返回顶部
返回头部 返回顶部