Centos6.4 安装Python2.7.10 & tornado-4.3
1、配置Centos6.4开发环境
安装相关依赖系统库
$ yum install wget gcc gcc-c++ zlib-devel gtk2-devel zip libart_lgpl-devel libXtst-devel -y
$ yum groupinstall "Development tools" -y
$ yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel -y
2、下载和安装Python
下载地址:https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz
Python-2.7.10.tgz
$ tar zxf Python-2.7.10.tgz
$ cd Python-2.7.10
$ ./configure --prefix=/usr/local
$ make && make altinstall
$ mv /usr/bin/python /usr/bin/python2.6.6.old
$ ln -s /usr/local/bin/python2.7 /usr/bin/python
$ python -V
Python 2.7.10
$ yum list
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python
这是因为yum默认使用的python版本是2.6.6,到哪是现在的python版本是2.7.10,故会出现上述问题,只需要该一下yum的默认python配置版本就行了:
$vi /usr/bin/yum
将文件头部的$!/usr/bin/python改为
$!/usr/bin/python2.6
3、下载安装Tornado
下载地址:https://pypi.python.org/simple/tornado/ 有很多版本随便选
$ tar zxf tornado-4.3.tar.gz
$ cd tornado-4.3
$ python setup.py build
$ python setup.py install
创建测试文件
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
application = tornado.web.Application([
(r"/", MainHandler),
])
if __name__ == "__main__":
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
4、运行文件
$ python tornado_example.py
然后打开浏览器,输入http://ip:8888就看到页面输出Hello, world了。