Installing Python2.6.7 On CentOS5

Source Link:
Install Python 2.6 on CentOS 5

CentOS 5 is the most common Python hosting environment in the market, but the default version of python it is 2.4 now. As some projects request the python version to be greater than V2.5, in this article, you will see how to install python 2.6 by compiling source code step by step.

1. Download python source from and Uncompress it.

$ wget
$ tar xzvf Python-2.6.7.tgz
2. Build & Install. In the source code folder:
$ ./configure –prefix=/opt/python2.6 –with-threads –enable-shared –with-zlib=/usr/include
$ make
$ make install
3. Add Python 2.6 lib to system lib. execute:
$ sudo ln -s /opt/python2.6/lib/ /usr/lib
$ sudo ln -s /opt/python2.6/lib/ /usr/lib

# Create necessary links and cache
$ sudo /sbin/ldconfig -v

# make a symbolic link to python
$ sudo ln -s /opt/python2.6/bin/python /usr/local/python
4. Check python version use “python -V”. If you still see old version of Python, you need to edit /etc/profile (as root), add the following line:
pathmunge /opt/python2.6/bin/
Above setting should be added before the line like:
Then re-login system, try “python -V” again. 5. After install yum, try “yum search php” This is to make sure we did not accidentally mess up “yum”, which is the biggest threat when upgrading Python version. If you see no errors, you should be good to start using Python 2.6.

Update python-MySQLdb

Python-OptParser Global args operations.

def setup_cmdline_parser():
    parser = _o.OptionParser()
    parser.add_option("-l", "--live", dest="live", action="store_true",
                      default=True, help = "show the ncurses live monitoring frontend (default)")
    parser.add_option("-n", "--notlive", dest="live", action="store_false",
                      default="True", help = "write to file instead of live monitoring")
    parser.add_option("-p", "--prefix", dest="prefix",
                      default = "log", help="prefix to use for output files")
    parser.add_option("-t", "--time", dest="duration", action="store", type="int", default=10,
            help="stop logging to file after this much time has elapsed (in seconds). set to 0 to keep logging indefinitely")
    return parser

def main():
    global options
    global args
    global domains

    parser = setup_cmdline_parser()
    (options, args) = parser.parse_args()

    if len(args):
        parser.error("No parameter required")
    if options.mspersample < 0:
        parser.error("option --ms_per_sample: invalid negative value: '%d'" %
    # If --ms_per_sample= is too large, no data may be logged.
    if not and options.duration != 0 and \
       options.mspersample > options.duration * 1000:
        parser.error("option --ms_per_sample: too large (> %d ms)" %
                     (options.duration * 1000))

            print 'Quitting.'

Using options, args out of functions with “global”

Python-Django clean_data 和 cleaned_data

clean_data 和 cleaned_data

>>>python shell
>>>from pageage1 import MyForm


>>>form.clean_data # Django 0.96
>>>form.cleaned_data # Django 1.0

HVS_system CGI scripts.


#!/usr/bin/env python
# -*- coding: UTF-8 -*-# enable debugging

import sys, os
import cgi
import MySQLdb
from urllib import *

host = ''
user = 'xxxxxx'
passwd = 'xxxxxxx'
db = 'asset'

print "Content-Type: text/plain;charset=utf-8"

form = cgi.FieldStorage()
request_host = form['request_host'].value 
request_status = form['status'].value

#check request_host
client_host = os.environ['REMOTE_ADDR']

if request_host != client_host:
    print "Error: illegal host request."
if request_status != '1':
    print "ERROR: Status %s cannot acceptable!" % request_status

cursor = conn.cursor()
sql_getstatus = 'select domu_name,status from hvs_domu_info where eth0 = "%s"' % request_host
n = cursor.execute(sql_getstatus)

#if not n:
#    print "Error: Bad request from host."
#    sys.exit(55)
rows = cursor.fetchall()
domu_name = rows[0][0]
status = rows[0][1]

print "Request_host : %s\nCheck status : %s" %(request_host,status)

def boot_status(status):
    if status == 0:
        boot = "off"
    elif status == 1:
        boot = "idle"
    elif status == 2:
        boot = "on"
        boot = "Uknown"
    return boot

if boot_status(status) == 'off':
    sql = 'update hvs_domu_info set status = 1 where eth0 ="%s"' % request_host
    e = cursor.execute(sql)
    n = cursor.execute(sql_getstatus)
    rows = cursor.fetchall()
    for row in rows:
        status = row[1]
        domu_id = row[0]
    print "Running status: %s" % boot_status(status)
    print "domu_id: %s" % domu_id
    print "Client host:%s" % client_host
elif boot_status(status) == 'on':
    print "Running status: %s" % boot_status(status)
    print "domu_id: %s" % domu_id
elif boot_status(status) == 'idle':
    print "domu_id: %s" % domu_name
    print "Warnning: Instance: %s already initialized." % domu_name

Python plugin setting with Vim

1. Go to:
Download the plugin which you need.

package script version date Vim version user release notes 1.2 2009-07-25 7.0 ryan kulla Added “from module” completion, Tab backwards support, and more third party libs.

Install details UNIX/LINUX: Place python_pydiction.vim in:  ~/.vim/after/ftplugin/

If this directory doesn’t already exist, create it. Vim looks there automatically.

WINDOWS: Assuming you installed Vim to C:\vim\, put python_pydiction.vim in C:\vim\vimfiles\ftplugin

You may install the other files (complete-dict and anywhere you want. For this example, we’ll assume you put them in C:\vim\vimfiles\ftplugin\pydiction\

Don’t put any files but python_pydiction.vim in the ftplugin directory, only .vim files should go there.

In your vimrc file, first add the following line to enable ftplugins:

filetype plugin on

then make sure you set “g:pydiction_location” to the full path of where you installed complete-dict, i.e.:

let g:pydiction_location = ‘C:/vim/vimfiles/ftplugin/pydiction/complete-dict’