Python 3.* 安装 web.py

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Webben/article/details/82495242

Python 3.* 安装 web.py

准备

官方文档:http://webpy.org/
Python 3 和 pip3

python -V           #Python 3.5.6
pip -V              #pip 18.0 from /usr/local/python/lib/python3.5/site-packages/pip (python 3.5)

安装 web.py

pip install web.py

报错:
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-pb8r7la9/web.p
You are using pip version 9.0.1, however version 18.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

根据引导

 pip install --upgrade pip
 # 成功以后
 pip install web.py

报错:
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-waqrvcqb/web.py/

指定更新 web.py 版本

pip install web.py==0.40.dev0

pip list      # 查看列表

成功。

测试

代码如下(注意换位)

vi /usr/script/web_build.py

#!/usr/bin/python
import web

urls = (
    '/(.*)', 'hello'
)
app = web.application(urls, globals())

class hello:        
    def GET(self, name):
        if not name: 
            name = 'World'
        return 'Hello, ' + name + '!'

if __name__ == "__main__":
    app.run()

运行服务

# 默认8080端口
/usr/bin/python /usr/script/web_build.py

# 使用其他端口
/usr/bin/python /usr/script/web_build.py 8088

访问:http://127.0.0.1:8080/

猜你喜欢

转载自blog.csdn.net/Webben/article/details/82495242