wynemo
12/2/2012 - 8:18 AM

install python2.6 on ubuntu12.04

install python2.6 on ubuntu12.04

###depencies

http://www.noah.org/wiki/Build_Python_2.6_on_Ubuntu

libssl-dev
libreadline-dev
aptitude -y -q install libc6-dev
aptitude -y -q install libffi4-dev
aptitude -y -q install libncurses5-dev
aptitude -y -q install libncursesw5-dev
aptitude -y -q install libbz2-dev
aptitude -y -q install libsqlite3-dev
aptitude -y -q install libgdbm-dev
aptitude -y -q install tcl8.4-dev
aptitude -y -q install tk8.4-dev

###patch and install

as ubuntu12.04 use python 2.7.3 by defaut, we should do some patches

http://ubuntuforums.org/showthread.php?t=1976837

  1. get python 2.6.8 source

     $ wget http://www.python.org/ftp/python/2.6.8/Python-2.6.8.tar.bz2
     $ tar xjvf Python-2.6.8.tar.bz2
     $ cd Python-2.6.8
    
  2. patch setup.py

    setup.patch

     --- setup.py       2012-04-10 17:32:11.000000000 +0200
     +++ setup.py       2012-05-08 12:42:23.893052724 +0200
     @@ -410,6 +410,7 @@
              lib_dirs = self.compiler.library_dirs + [
                  '/lib64', '/usr/lib64',
                  '/lib', '/usr/lib',
     +            '/usr/lib/x86_64-linux-gnu'
                  ]
              inc_dirs = self.compiler.include_dirs + ['/usr/include']
              exts = []
    
  3. patch _ssl.c

    python 2.7.3 seems not support sslv2

     $ vim /usr/lib/python2.7/ssl.py
    

    then you can see

     from _ssl import PROTOCOL_SSLv3, PROTOCOL_SSLv23, PROTOCOL_TLSv1
     _PROTOCOL_NAMES = {
         PROTOCOL_TLSv1: "TLSv1",
         PROTOCOL_SSLv23: "SSLv23",
         PROTOCOL_SSLv3: "SSLv3",
     }
     try:
         from _ssl import PROTOCOL_SSLv2
     except ImportError:
         pass
     else:
         _PROTOCOL_NAMES[PROTOCOL_SSLv2] = "SSLv2"
    

    _ssl.patch

     --- Modules/_ssl.c      2012-04-10 17:32:09.000000000 +0200
     +++ Modules/_ssl.c      2012-05-08 17:50:46.929523605 +0200
     @@ -302,8 +302,8 @@
              self->ctx = SSL_CTX_new(TLSv1_method()); /* Set up context */
          else if (proto_version == PY_SSL_VERSION_SSL3)
              self->ctx = SSL_CTX_new(SSLv3_method()); /* Set up context */
     -    else if (proto_version == PY_SSL_VERSION_SSL2)
     -        self->ctx = SSL_CTX_new(SSLv2_method()); /* Set up context */
     +/*    else if (proto_version == PY_SSL_VERSION_SSL2)
     +        self->ctx = SSL_CTX_new(SSLv2_method());*/ /* Set up context */
          else if (proto_version == PY_SSL_VERSION_SSL23)
              self->ctx = SSL_CTX_new(SSLv23_method()); /* Set up context */
          PySSL_END_ALLOW_THREADS
     @@ -1688,8 +1688,8 @@
                                  PY_SSL_CERT_REQUIRED);
    
          /* protocol versions */
     -    PyModule_AddIntConstant(m, "PROTOCOL_SSLv2",
     -                            PY_SSL_VERSION_SSL2);
     +/*    PyModule_AddIntConstant(m, "PROTOCOL_SSLv2",
     +                            PY_SSL_VERSION_SSL2);*/
          PyModule_AddIntConstant(m, "PROTOCOL_SSLv3",
                                  PY_SSL_VERSION_SSL3);
          PyModule_AddIntConstant(m, "PROTOCOL_SSLv23",
    
  4. configure and make

     $ env CPPFLAGS="-I/usr/lib/x86_64-linux-gnu" LDFLAGS="-L/usr/include/x86_64-linux-gnu" ./configure
     $ make
    
  5. patch ssl.py ssl.patch

     --- Lib/ssl.py  2012-04-10 17:32:06.000000000 +0200
     +++ Lib/ssl.py       2012-05-08 17:51:34.029522977 +0200
     @@ -61,7 +61,7 @@
    
      from _ssl import SSLError
      from _ssl import CERT_NONE, CERT_OPTIONAL, CERT_REQUIRED
     -from _ssl import PROTOCOL_SSLv2, PROTOCOL_SSLv3, PROTOCOL_SSLv23, PROTOCOL_TLSv1
     +from _ssl import PROTOCOL_SSLv3, PROTOCOL_SSLv23, PROTOCOL_TLSv1
      from _ssl import RAND_status, RAND_egd, RAND_add
      from _ssl import \
           SSL_ERROR_ZERO_RETURN, \
    
  6. install

     $ sudo make install
    
  7. restore python2.7 as system defautl

     $ sudo ln -f /usr/bin/python2.7 /usr/local/bin/python