1. 程式人生 > >Windows下安裝Web.py快速指南

Windows下安裝Web.py快速指南

環境介紹

首先介紹下安裝使用的環境
- Windows 7
- Python 3.6

Web.py介紹

web.py是Python在Web領域一個輕量級的解決方案,所謂輕量,就是非常簡單快速滿足Web頁面開發的需求。
首先來感受一下其輕量的程度吧:

import web

urls = (
    '/(.*)', 'hello'
)

class hello:
    def GET(self, name):
        i = web.input(times=1)
        if not name: name = 'world'
        for c in
xrange(int(i.times)): print 'Hello,', name+'!' if __name__ == "__main__": web.run(urls, globals())

綜合來看,是不是非常的輕量….

安裝指南

目前預設的web.py版本是0.38, 只要是針對python2而打包的,針對Python3是無法通過pip3的方式來直接安裝的:
在安裝之前,需要提前安裝2個依賴包:

pip3 install db
pip install utils

直接安裝web.py會報出若干錯誤資訊:

C:\Users\xx>pip3 install web.py
Collecting web.py
Using cached web.py-0.38.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File “”, line 1, in
File “C:\Users\CHENJU~1\AppData\Local\Temp\pip-build-vxm84t4s\web.py\setup.py”, line 6, in
from web import version


File “C:\Users\CHENJU~1\AppData\Local\Temp\pip-build-vxm84t4s\web.py\web__init__.py”, line 14, in
import utils, db, net, wsgi, http, webapi, httpserver, debugerror
File “d:\program files\python\lib\site-packages\db__init__.py”, line 69
print “var”, var
^
SyntaxError: Missing parentheses in call to ‘print’

----------------------------------------

Command “python setup.py egg_info” failed with error code 1 in C:\Users\xx~1\AppData\Local\Temp\pip-build-vxm84t
從錯誤資訊來看,其錯誤為print在不同的Python版本下的語法上的差異造成的。

待下載完成之後,進入下載目錄,進行安裝:

python setup.py install

結果資訊:

D:\OpenSource\webpy>python setup.py install
D:\Program Files\python\lib\site-packages\setuptools\dist.py:331: UserWarning: Normalizing ‘0.40-dev0’ to ‘0.40.dev0’
normalized_version,
running install
running bdist_egg
running egg_info
creating web.py.egg-info
writing web.py.egg-info\PKG-INFO
writing dependency_links to web.py.egg-info\dependency_links.txt
writing top-level names to web.py.egg-info\top_level.txt
writing manifest file ‘web.py.egg-info\SOURCES.txt’
reading manifest file ‘web.py.egg-info\SOURCES.txt’
writing manifest file ‘web.py.egg-info\SOURCES.txt’
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
creating build
creating build\lib
creating build\lib\web
copying web\application.py -> build\lib\web
copying web\browser.py -> build\lib\web
copying web\db.py -> build\lib\web
copying web\debugerror.py -> build\lib\web
copying web\form.py -> build\lib\web
copying web\http.py -> build\lib\web
copying web\httpserver.py -> build\lib\web
copying web\net.py -> build\lib\web
copying web\py3helpers.py -> build\lib\web
copying web\session.py -> build\lib\web
copying web\template.py -> build\lib\web
copying web\test.py -> build\lib\web
copying web\utils.py -> build\lib\web
copying web\webapi.py -> build\lib\web
copying web\webopenid.py -> build\lib\web
copying web\wsgi.py -> build\lib\web
copying web__init__.py -> build\lib\web
creating build\lib\web\wsgiserver
copying web\wsgiserver\ssl_builtin.py -> build\lib\web\wsgiserver
copying web\wsgiserver\ssl_pyopenssl.py -> build\lib\web\wsgiserver
copying web\wsgiserver\wsgiserver2.py -> build\lib\web\wsgiserver
copying web\wsgiserver\wsgiserver3.py -> build\lib\web\wsgiserver
copying web\wsgiserver__init__.py -> build\lib\web\wsgiserver
creating build\lib\web\contrib
copying web\contrib\template.py -> build\lib\web\contrib
copying web\contrib__init__.py -> build\lib\web\contrib
creating build\bdist.win-amd64
creating build\bdist.win-amd64\egg
creating build\bdist.win-amd64\egg\web
copying build\lib\web\application.py -> build\bdist.win-amd64\egg\web
copying build\lib\web\browser.py -> build\bdist.win-amd64\egg\web
creating build\bdist.win-amd64\egg\web\contrib
copying build\lib\web\contrib\template.py -> build\bdist.win-amd64\egg\web\contrib
copying build\lib\web\contrib__init__.py -> build\bdist.win-amd64\egg\web\contrib
copying build\lib\web\db.py -> build\bdist.win-amd64\egg\web
copying build\lib\web\debugerror.py -> build\bdist.win-amd64\egg\web
copying build\lib\web\form.py -> build\bdist.win-amd64\egg\web
copying build\lib\web\http.py -> build\bdist.win-amd64\egg\web
copying build\lib\web\httpserver.py -> build\bdist.win-amd64\egg\web
copying build\lib\web\net.py -> build\bdist.win-amd64\egg\web
copying build\lib\web\py3helpers.py -> build\bdist.win-amd64\egg\web
copying build\lib\web\session.py -> build\bdist.win-amd64\egg\web
copying build\lib\web\template.py -> build\bdist.win-amd64\egg\web
copying build\lib\web\test.py -> build\bdist.win-amd64\egg\web
copying build\lib\web\utils.py -> build\bdist.win-amd64\egg\web
copying build\lib\web\webapi.py -> build\bdist.win-amd64\egg\web
copying build\lib\web\webopenid.py -> build\bdist.win-amd64\egg\web
copying build\lib\web\wsgi.py -> build\bdist.win-amd64\egg\web
creating build\bdist.win-amd64\egg\web\wsgiserver
copying build\lib\web\wsgiserver\ssl_builtin.py -> build\bdist.win-amd64\egg\web\wsgiserver
copying build\lib\web\wsgiserver\ssl_pyopenssl.py -> build\bdist.win-amd64\egg\web\wsgiserver
copying build\lib\web\wsgiserver\wsgiserver2.py -> build\bdist.win-amd64\egg\web\wsgiserver
copying build\lib\web\wsgiserver\wsgiserver3.py -> build\bdist.win-amd64\egg\web\wsgiserver
copying build\lib\web\wsgiserver__init__.py -> build\bdist.win-amd64\egg\web\wsgiserver
copying build\lib\web__init__.py -> build\bdist.win-amd64\egg\web
byte-compiling build\bdist.win-amd64\egg\web\application.py to application.cpython-36.pyc
byte-compiling build\bdist.win-amd64\egg\web\browser.py to browser.cpython-36.pyc
byte-compiling build\bdist.win-amd64\egg\web\contrib\template.py to template.cpython-36.pyc
byte-compiling build\bdist.win-amd64\egg\web\contrib__init__.py to init.cpython-36.pyc
byte-compiling build\bdist.win-amd64\egg\web\db.py to db.cpython-36.pyc
byte-compiling build\bdist.win-amd64\egg\web\debugerror.py to debugerror.cpython-36.pyc
byte-compiling build\bdist.win-amd64\egg\web\form.py to form.cpython-36.pyc
byte-compiling build\bdist.win-amd64\egg\web\http.py to http.cpython-36.pyc
byte-compiling build\bdist.win-amd64\egg\web\httpserver.py to httpserver.cpython-36.pyc
byte-compiling build\bdist.win-amd64\egg\web\net.py to net.cpython-36.pyc
byte-compiling build\bdist.win-amd64\egg\web\py3helpers.py to py3helpers.cpython-36.pyc
byte-compiling build\bdist.win-amd64\egg\web\session.py to session.cpython-36.pyc
byte-compiling build\bdist.win-amd64\egg\web\template.py to template.cpython-36.pyc
byte-compiling build\bdist.win-amd64\egg\web\test.py to test.cpython-36.pyc
byte-compiling build\bdist.win-amd64\egg\web\utils.py to utils.cpython-36.pyc
byte-compiling build\bdist.win-amd64\egg\web\webapi.py to webapi.cpython-36.pyc
byte-compiling build\bdist.win-amd64\egg\web\webopenid.py to webopenid.cpython-36.pyc
byte-compiling build\bdist.win-amd64\egg\web\wsgi.py to wsgi.cpython-36.pyc
byte-compiling build\bdist.win-amd64\egg\web\wsgiserver\ssl_builtin.py to ssl_builtin.cpython-36.pyc
byte-compiling build\bdist.win-amd64\egg\web\wsgiserver\ssl_pyopenssl.py to ssl_pyopenssl.cpython-36.pyc
byte-compiling build\bdist.win-amd64\egg\web\wsgiserver\wsgiserver2.py to wsgiserver2.cpython-36.pyc
File “build\bdist.win-amd64\egg\web\wsgiserver\wsgiserver2.py”, line 1019
except socket.error, e:
^
SyntaxError: invalid syntax

byte-compiling build\bdist.win-amd64\egg\web\wsgiserver\wsgiserver3.py to wsgiserver3.cpython-36.pyc
byte-compiling build\bdist.win-amd64\egg\web\wsgiserver__init__.py to init.cpython-36.pyc
byte-compiling build\bdist.win-amd64\egg\web__init__.py to init.cpython-36.pyc
creating build\bdist.win-amd64\egg\EGG-INFO
copying web.py.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying web.py.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying web.py.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying web.py.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
zip_safe flag not set; analyzing archive contents…
web.pycache.application.cpython-36: module references file
web.pycache.debugerror.cpython-36: module references file
creating dist
creating ‘dist\web.py-0.40.dev0-py3.6.egg’ and adding ‘build\bdist.win-amd64\egg’ to it
removing ‘build\bdist.win-amd64\egg’ (and everything under it)
Processing web.py-0.40.dev0-py3.6.egg
creating d:\program files\python\lib\site-packages\web.py-0.40.dev0-py3.6.egg
Extracting web.py-0.40.dev0-py3.6.egg to d:\program files\python\lib\site-packages
File “d:\program files\python\lib\site-packages\web.py-0.40.dev0-py3.6.egg\web\wsgiserver\wsgiserver2.py”, line 1019
except socket.error, e:
^
SyntaxError: invalid syntax

Adding web.py 0.40.dev0 to easy-install.pth file

Installed d:\program files\python\lib\site-packages\web.py-0.40.dev0-py3.6.egg
Processing dependencies for web.py==0.40.dev0
Finished processing dependencies for web.py==0.40.dev0

從結果資訊來看,其中依然存在若干錯誤資訊,對於Python3而言,這些都是在python2下的語法在Python 3下無法被正確解析的問題,估計在後續版本,可以將python2的內容在python 3的分支上逐步更新。

目前的這個分支還是dev分支,存在若干問題還是可以理解的。

總結

web.py的這位作者已經仙逝,繼任者還需努力,繼續更新呀,從github上最後一次提交是在2017年初,不知道是否絕版了……