Python 2.7

Print Friendly, PDF & Email

Our main servers are running older versions of Python, which is good and stable for the server, but may not be what users want.  In this post, I’m installing another version of Python, specifically 2.7.  Since it’s not the standard version, I can’t use yum.

Following the advice from this StackOverflow post on multiple versions of Python, I went to http://www.python.org/getit/releases/2.7/, and got the URL of a tgz file and did:

[root@puma tmp] curl http://www.python.org/ftp/python/2.7/Python-2.7.tgz > Python-2.7.tgz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 13.3M  100 13.3M    0     0   633k      0  0:00:21  0:00:21 --:--:-- 1174k
[root@puma tmp] tar xzf Python-2.7.tgz 
[root@puma tmp] cd Python-2.7
[root@puma Python-2.7] ./configure 
checking for --enable-universalsdk... no
checking for --with-universal-archs... 32-bit
checking MACHDEP... linux2
checking EXTRAPLATDIR... 
checking machine type as reported by uname -m... x86_64
checking for --without-gcc... no
checking for gcc... gcc
... // many lines omitted
checking for build directories... done
configure: creating ./config.status
config.status: creating Makefile.pre
config.status: creating Modules/Setup.config
config.status: creating Misc/python.pc
config.status: creating pyconfig.h
creating Modules/Setup
creating Modules/Setup.local
creating Makefile
[root@puma Python-2.7]

Now, reading the README file says that in order to build the sqlite3 package, I’ll need to have those libraries and headers installed on my system.  Let’s check:

[root@puma Python-2.7] grep sqlite3 /var/log/rpmpkgs
[root@puma Python-2.7] grep sqlite /var/log/rpmpkgs
python-sqlite-1.1.7-1.2.1.x86_64.rpm
sqlite-3.3.6-5.i386.rpm
sqlite-3.3.6-5.x86_64.rpm
sqlite-devel-3.3.6-5.x86_64.rpm
[root@puma Python-2.7] yum search sqlite
================================================================================ Matched: sqlite =================================================================================
mono-data-sqlite.x86_64 : sqlite database connectivity for Mono
pdns-backend-sqlite.x86_64 : SQLite backend for pdns
php-pear-Log.noarch : Abstracted logging facility for PHP
python-sqlite.x86_64 : Python bindings for sqlite.
qt4-sqlite.x86_64 : SQLite drivers for Qt's SQL classes
sqlite.i386 : Library that implements an embeddable SQL database engine
sqlite.x86_64 : Library that implements an embeddable SQL database engine
sqlite-devel.i386 : Development tools for the sqlite3 embeddable SQL database engine.
sqlite-devel.x86_64 : Development tools for the sqlite3 embeddable SQL database engine.
[root@puma Python-2.7] yum search sqlite3
================================================================================ Matched: sqlite3 ================================================================================
sqlite-devel.i386 : Development tools for the sqlite3 embeddable SQL database engine.
sqlite-devel.x86_64 : Development tools for the sqlite3 embeddable SQL database engine.
[root@puma Python-2.7] yum -y install sqlite3
No package sqlite3 available.
Nothing to do
[root@puma Python-2.7]

Okay, now make the binaries:

[root@puma Python-2.7] make
gcc -pthread -c -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes  -I. -IInclude -I./Include   -DPy_BUILD_CORE -o Modules/python.o ./Modules/python.c
gcc -pthread -c -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes  -I. -IInclude -I./Include   -DPy_BUILD_CORE -o Parser/acceler.o Parser/acceler.c
gcopying and adjusting /var/tmp/Python-2.7/Lib/smtpd.py -> build/scripts-2.7
... many lines omitted
changing mode of build/scripts-2.7/pydoc from 660 to 775
changing mode of build/scripts-2.7/idle from 660 to 775
changing mode of build/scripts-2.7/2to3 from 660 to 775
changing mode of build/scripts-2.7/smtpd.py from 660 to 775
/usr/bin/install -c -m 644 ./Tools/gdb/libpython.py python-gdb.py
[root@puma Python-2.7]

Now, usually we would then to “make install,” but that would overwrite the default python.  To make it live side-by-side, just use make “altinstall.”  Here are the relevant lines of the README;

Installing multiple versions
----------------------------

On Unix and Mac systems if you intend to install multiple versions of Python
using the same installation prefix (--prefix argument to the configure
script) you must take care that your primary python executable is not
overwritten by the installation of a different version.  All files and
directories installed using "make altinstall" contain the major and minor
version and can thus live side-by-side.  "make install" also creates
${prefix}/bin/python which refers to ${prefix}/bin/pythonX.Y.  If you intend
to install multiple versions using the same prefix you must decide which
version (if any) is your "primary" version.  Install that version using
"make install".  Install all other versions using "make altinstall".

For example, if you want to install Python 2.5, 2.6 and 3.0 with 2.6 being
the primary version, you would execute "make install" in your 2.6 build
directory and "make altinstall" in the others.

So, let’s do that:

[root@puma Python-2.7] make altinstall
/usr/bin/install -c python /usr/local/bin/python2.7
if test -f libpython2.7.a; then \
        if test -n "" ; then \
            /usr/bin/install -c -m 555  /usr/local/bin; \
        else \
            /usr/bin/install -c -m 555 libpython2.7.a /usr/local/lib/libpython2.7.a; \
            if test libpython2.7.a != libpython2.7.a; then \
                (cd /usr/local/lib; ln -sf libpython2.7.a libpython2.7.a) \
            fi \
        fi; \
    else    true; \
    fi
running build
running build_ext
building dbm using gdbm

Python build finished, but the necessary bits to build these modules were not found:
bsddb185           dl                 imageop         
sunaudiodev                                           
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

running build_scripts
Creating directory /usr/local/lib/python2.7
Creating directory /usr/local/lib/python2.7/lib-tk
Creating directory /usr/local/lib/python2.7/lib-tk/test
Creating directory /usr/local/lib/python2.7/lib-tk/test/test_tkinter
Creating directory /usr/local/lib/python2.7/lib-tk/test/test_ttk
Creating directory /usr/local/lib/python2.7/site-packages
Creating directory /usr/local/lib/python2.7/test
....thousands of additional lines omitted
/usr/bin/install -c -m 644 ./Lib/_abcoll.py /usr/local/lib/python2.7
/usr/bin/install -c -m 644 ./Lib/abc.py /usr/local/lib/python2.7
/usr/bin/install -c -m 644 ./Lib/aifc.py /usr/local/lib/python2.7
/usr/bin/install -c -m 644 ./Lib/antigravity.py /usr/local/lib/python2.7
/usr/bin/install -c -m 644 ./Lib/anydbm.py /usr/local/lib/python2.7
/usr/bin/install -c -m 644 ./Lib/argparse.py /usr/local/lib/python2.7
/usr/bin/install -c -m 644 ./Lib/ast.py /usr/local/lib/python2.7
/usr/bin/install -c -m 644 ./Lib/asynchat.py /usr/local/lib/python2.7
...thousands of additional lines omitted
changing mode of /usr/local/bin/2to3 to 775
running install_egg_info
Writing /usr/local/lib/python2.7/lib-dynload/Python-2.7-py2.7.egg-info
[root@puma Python-2.7]

Whew!  That took *forever*.  Let’s see what it did:

[root@puma Python-2.7] ls -l /usr/local/bin/python2.7*
-rwxr-xr-x 1 root root 6053555 Aug 29 15:35 /usr/local/bin/python2.7
-rwxr-xr-x 1 root root    1624 Aug 29 15:42 /usr/local/bin/python2.7-config
[root@puma Python-2.7] ls -l /usr/local/bin/easy_install*
-rwxr-xr-x 1 root root 292 Nov 19  2010 /usr/local/bin/easy_install
-rwxr-xr-x 1 root root 300 Nov 19  2010 /usr/local/bin/easy_install-2.6
[root@puma Python-2.7] which python
/usr/bin/python
[root@puma Python-2.7] python -V
Python 2.4.3
[root@puma Python-2.7] python2.7 -V
Python 2.7

Hmm.  I like that the basic Python hasn’t changed and we have python2.7.  I had hoped there would also be easy_install-2.7, as there is for -2.6.  We’ll have to look into that.  Still, this is a good start.

Ah, found the solution for easy_install and pip from http://mythinkpond.wordpress.com/2011/12/28/how-to-upgrade-to-python-2-7-on-centos/.  I’ve followed those directions to install easy_install-2.7 and pip-2.7 on Puma and Tempest.  There are just two modifications of the linked directions. Since we don’t want to replace the default python on either server, we will do:

make altinstall   # instead of make install
cd pip-1.0
python2.7 setup.py install   # instead of python setup.py install

Seems to be working well!

 

 

 

 

 

 

 

 

About CS SysAdmins

The CS Department System Administrators
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *