CentOS6.5_64 安装python3.4.0rc3 测试

CentOS6.5_x64操作系统自带的是python2.6.6r266。
升级操作系统
yum makecache
yum -y update
yum -y upgrade
yum -y install gcc* gcc-c++ sysstat ncurses ncurses-devel make automake openssl* zlib*
yum -y install vim ntpdate lsof setuptool net-snmp tcpdump zip unzip svn wget curl git
yum -y install libevent libevent-devel uuid-devel libboost libboost-devel gd gd-*
yum -y install crontabs net-tools ntpdate
yum -y install mysql-client mysql-devel
yum -y groupinstall “Chinese Support”
ntpdate pool.ntp.org

开始安装python
wget https://www.python.org/ftp/python/3.4.0/Python-3.4.0rc3.tgz

/bin/tar zxvf Python-3.4.0rc3.tgz
cd Python-3.4.0rc3
./configure
make && make install

运行速度测试代码参考:http://www.simonzhang.net/?p=1844

python 2.7.6rc1 测试结果如下:

20.5176548958

real 0m20.568s
user 0m20.546s
sys 0m0.025s

Python-3.4.0rc3 测试结果如下:

18.61501383781433

real 0m18.674s
user 0m18.656s
sys 0m0.010s

python-3.4 自带pip工具
pip3 install PyMySQL
pip3 install tornado
pip3 install torndb

#!/bin/python
#-*- coding:utf-8 -*-
# Filename:    testpython3.py
# Revision:    1.0
# Date:        2014-09-22
# Author:      simonzhang
# web:         www.simonzhang.net
# Email:       simon-zzm@163.com
### END INIT INFO
import pymysql

def sql_comm(sql_run,comm):
    try:
        conn = pymysql.connect(host = '192.168.0.1', \
                               port = 3306, \
                               user = 'test', passwd = '123456', \
                               db = 'tt', charset = 'utf8', \
                               connect_timeout = 30)
    except pymysql.MySQLError:
        pass
    cur = conn.cursor()
    try:
        cur.execute(sql_run)
        if comm == 'y':
            cur.execute("commit")
        result_set = cur.fetchall()
        return(result_set)
        cur.close()
        db.close()
    except:
        pass


if __name__== '__main__':
    sql_run = "select count(*) from user"
    comm = "n"
    _get = sql_comm(sql_run, comm)
    print(_get)

总结python3的语法更标准化,但是速度提升不明显。通过查询资料显示第三方库的稳定性也是不特别好。所以当前我还是老老实实使用python2。

发表评论

电子邮件地址不会被公开。 必填项已用*标注