安装python最新版本:
第一,请确保使用下面命令安装web.py
pip install web.py==0.40-dev1
第二、运行官方例子:
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()
第三、出现如下错误提示:
Traceback (most recent call last): File "D:\Program Files\Python\Python37\lib\site-packages\web\utils.py", line 526, in take yield next(seq) StopIteration The above exception was the direct cause of the following exception: Traceback (most recent call last): File "D:\Python\hello.py", line 6, in <module> app = web.application(urls, globals(),True) File "D:\Program Files\Python\Python37\lib\site-packages\web\application.py", line 62, in __init__ self.init_mapping(mapping) File "D:\Program Files\Python\Python37\lib\site-packages\web\application.py", line 130, in init_mapping self.mapping = list(utils.group(mapping, 2)) File "D:\Program Files\Python\Python37\lib\site-packages\web\utils.py", line 531, in group x = list(take(seq, size)) RuntimeError: generator raised StopIteration
修改Lib\site-packages\web 下的utils.py文件。
将第526行的
yield next(seq)
改为
try: yield next(seq) except StopIteration: return
注意!注意!可能会报错。
问题:Python文件运行时报TabError: inconsistent use of tabs and spaces in indentation
原因:说明Python文件中混有Tab和Space用作格式缩进。这通常是使用外部编辑器编辑Python文件时,自动采用Tab进行格式缩进。
解决:将Tab转换成4个Space(通常)或者用Python编辑器(如pyDev)格式化。
用普通编辑器编辑后,可能是这样。
正常启动应该是这样子:
浏览器中输入:http://127.0.0.1:8080/