学习下网站制作,比较了一下,选择了tornado服务器,因此想着搭建一个开发环境,没想到第一步就碰到问题了。在 https://pypi.org/project/tornado/#files 下了最新的tornado,解压安装后,在Python中测试,import tornado,OK,没问题,但是执行测试脚本时,却出现错误:
from singledispatch import singledispatch # backport
ImportError: No module named singledispatch
网上查,说是某些tornado版本不支持singledispatch,所以需要换个方法安装,在线的,sudo easy_install tornado,但是爆出错误:
Download error on https://pypi.python.org/simple/singledispatch/: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:661) — Some packages may not be found!
Couldn’t find index page for ‘singledispatch’ (maybe misspelled?)
竟然还是这个问题!!!
没办法,直接下载singledispatch安装,https://pypi.org/project/singledispatch/,一路缺文件,一路安装,最后,终于把tornado装上了。
用代码测试:python hell.py –port=1234
然后打开网站 http://localhost:1234/,输出成功!
附测试代码:
- #! /usr/bin/python
- # -*- coding:utf-8 -*-
- import tornado.httpserver
- import tornado.ioloop
- #import tornado.options
- import tornado.web
- from tornado.options import define, options
- define(“port”, default=8000, help=”run on the given port”, type=int)
- class IndexHandler(tornado.web.RequestHandler):
- def get(self):
- greeting = self.get_argument(‘greeting’, ‘Hello’)
- self.write(greeting + ‘, tornado!’)
- if __name__ == “__main__“:
- tornado.options.parse_command_line()
- app = tornado.web.Application(handlers=[(r”/”, IndexHandler)])
- http_server = tornado.httpserver.HTTPServer(app)
- http_server.listen(options.port)
- tornado.ioloop.IOLoop.instance().start()