python3安装web.py

今天准备测试代理池IPProxyPool获取到ip的质量,在安装web.py的时候遇到了些问题,在此记录一下。

1.安装资料

web.py官网:http://webpy.org/

web.py的github地址:https://github.com/webpy/webpy/

2.安装

方法1:(推荐)

pip install web.py==0.40-dev1

方法2:

注意:这个是使用linux软连接方式

git clone git://github.com/webpy/webpy.git
ln -s `pwd`/webpy/web .

方法3(从源码处安装):

git clone https://github.com/webpy/webpy.git
cd webpy
python setup.py install
pip list

3.问题

3.1.python2与python3问题

pip install web.py

 上面安装命令只支持python2,官网上已经说明过。这样安装会报错:

ERROR: Command errored out with exit status 1:
     command: 'e:programpythonpython.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\peng\AppData\Local\Temp\pip-install-ubdky_a3\web.py\setup.py'"'"'; __file__='"'"'C:\Users\peng\AppData\Local\Temp\pip-install-ubdky_a3\web.py\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'
'"'"', '"'"'
'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: C:UserspengAppDataLocalTemppip-install-ubdky_a3web.py
    Complete output (7 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:UserspengAppDataLocalTemppip-install-ubdky_a3web.pysetup.py", line 6, in <module>
        from web import __version__
      File "C:UserspengAppDataLocalTemppip-install-ubdky_a3web.pyweb\__init__.py", line 14, in <module>
        import utils, db, net, wsgi, http, webapi, httpserver, debugerror
    ModuleNotFoundError: No module named 'utils'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

 主要是这个错误:

Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:UserspengAppDataLocalTemppip-install-ubdky_a3web.pysetup.py", line 6, in <module>
        from web import __version__
      File "C:UserspengAppDataLocalTemppip-install-ubdky_a3web.pyweb\__init__.py", line 14, in <module>
        import utils, db, net, wsgi, http, webapi, httpserver, debugerror
    ModuleNotFoundError: No module named 'utils'

原因是,除了0.40-dev1版本支持python3外其他版本都不支持(测试过webpy-0.39

github上的版本:https://github.com/webpy/webpy/tags

3.2.测试hello world出错

官网例子:

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 "E:Programpythonlibsite-packageswebutils.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 ".	est_web.py", line 6, in <module>
    app = web.application(urls, globals())
  File "E:Programpythonlibsite-packageswebapplication.py", line 62, in __init__
    self.init_mapping(mapping)
  File "E:Programpythonlibsite-packageswebapplication.py", line 130, in init_mapping
    self.mapping = list(utils.group(mapping, 2))
  File "E:Programpythonlibsite-packageswebutils.py", line 531, in group
    x = list(take(seq, size))
RuntimeError: generator raised StopIteration

解决方法:

修改Libsite-packagesweb 下的utils.py文件,在526行

源码:

def take(seq, n):
        for i in range(n):
            yield next(seq)

修改后:

def take(seq, n):
        for i in range(n):
            try:
                yield next(seq)
            except StopIteration:
                return

运行:

访问http://localhost:8080/

原文地址:https://www.cnblogs.com/SmilingEye/p/11289059.html