Home

Software
 Open Source Software 
 Commercial Software

Articles Authored

Hire Me
 Desired Types of Work
 Areas of Expertise
 Résumé
 Portfolio

Contact Us

Why would anyone name a technology company Red Mule? Here's the story.

Verse for the Day Behold, the tabernacle of God is with men, and he will dwell with them, and they shall be his people, and God himself shall be with them, and be their God.
Rev 21:3

 

Compile and Install Python 2.5 on HostMonster

Python is my favorite programming language and I'm using it extensively on this web site (and others). Unfortunately HostMonster only offers a very old version of Python (v2.3.4) which is missing many convenient features that are available in the latest version. Here's how to download, compile and install the latest (2.5.x) version of Python and make it available to all your HostMonster Python programs.

Preliminaries

When we get to the installation step later we will need a place to put the compiled Python binaries, so let's create it now.

$ mkdir ~/python

(Note: I chose to put everything python-related in ~/python. A more standard Unix-like location would probably be ~/bin. So you might want to do that instead. If so, adjust anything below that refers to ~/python or /home/myuser/python to end in "bin" instead.)

Download and Unpack

Go to the Python download page and get a link to the source distribution for the latest version. Now use 'wget' to download it to your HostMonster account.

$ wget http://python.org/ftp/python/2.5.1/Python-2.5.1.tar.bz2
$ bunzip2 Python-2.5.1.tar.bz2
$ tar xvf Python-2.5.1.tar
$ cd Python-2.5.1

Review the Build Instructions

The build instructions are located in the 'README' file.

$ less README
I'll save you some trouble, the relevant sections are clipped out here:

To start building right away (on UNIX): type "./configure" in the
current directory and when it finishes, type "make".  This creates an
executable "./python"; to install in /usr/local, first do "su root"
and then "make install".

Installing
----------
To install the Python binary, library modules, shared library modules
(see below), include files, configuration files, and the manual page,
just type

        make install

This will install all platform-independent files in subdirectories of
the directory given with the --prefix option to configure or to the
`prefix' Make variable (default /usr/local).  All binary and other
platform-specific files will be installed in subdirectories if the
directory given by --exec-prefix or the `exec_prefix' Make variable
(defaults to the --prefix directory) is given.

If DESTDIR is set, it will be taken as the root directory of the
installation, and files will be installed into $(DESTDIR)$(prefix),
$(DESTDIR)$(exec_prefix), etc.

Configuration options and variables
-----------------------------------
--prefix, --exec-prefix: If you want to install the binaries and the
        Python library somewhere else than in /usr/local/{bin,lib},
        you can pass the option --prefix=DIRECTORY; the interpreter
        binary will be installed as DIRECTORY/bin/python and the
        library files as DIRECTORY/lib/python/*.  If you pass
        --exec-prefix=DIRECTORY (as well) this overrides the
        installation prefix for architecture-dependent files (like the
        interpreter binary).  Note that --prefix=DIRECTORY also
        affects the default module search path (sys.path), when
        Modules/config.c is compiled.  Passing make the option
        prefix=DIRECTORY (and/or exec_prefix=DIRECTORY) overrides the
        prefix set at configuration time; this may be more convenient
        than re-running the configure script if you change your mind
        about the install prefix.
So from that we know we know we will be doing './configure, make, and make install' and giving configure an option to indicate we're installing in an alternate location. No surprises there.

I suggest you begin by starting a screen session. In case your connection is lost to HostMonster, the running step can still complete.

$ screen
$ ./configure --prefix=/home/myuser/python
There will be lots of output from configure. Just make sure there are no errors at the end. Now compile everything.

$ make
That only took 2-3 minutes, not bad. Make sure there were no errors. Now install it to our alternate location.

$ make install
This scrolls a huge amount of output. Just make sure there are no errors. If you've made it this far, we're now ready to see if we actually got something that looks like a Python binary.

$ cd ~/python/bin
$ ls
idle  pydoc  python  python-config  python2.5  python2.5-config  smtpd.py
Looks normal. Now let's see if it will run.

$ ./python
Python 2.5.1 (r251:54863, Jan 24 2008, 10:10:36)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> import sys
Note the version (2.5.1). If that all ran with no errors we're good to go.

Finalization

Now we need to make this our default installation of Python, else everything will likely still try to use the system-wide older Python.

Use vi to edit your .bashrc file.

$ vi ~/.bashrc
You'll need lines at the bottom something like this:

PATH=~/python/bin:$PATH
The part I added is the first part. Once we log in again, our python/bin directory will be searched first and that Python should always be found rather the one found later in the path.

The last step - and somewhat more tedious - is that you need to replace the "execute" line at the top of every Python source file we have. Say you have a program called 'example.py'. The first line probably looks something like this:

#!/usr/bin/python
That points to the system-wide python located in /usr/bin. Change it to point to our later python at the alternate install location.

#!/home/myuser/python/bin/python

Done

Now everything run in your account should use that new Python by default.

Your questions and comments are welcome at comments@redmule.com

 Front Sight
 Free Gun
Home  ∴  Contact Us  ∴  Webmaster
Copyright© 2000-2008 Red Mule Technology.  All Rights Reserved.
Firefox 2 Get Thunderbird! Front Sight Challenge - Front Sight's New Reality Show Program with Python!