Installing Python 2.5 on Bluehost

October 20th, 2008 at 6:52 pm

Bluehost is my hosting provider for http://thegreenplace.net

I’m generally quite happy with them – the service is stable and the support is responsive. A small annoyance is the old version of Python they have installed by default – 2.3.4. This is quite an old version and many libraries have already dropped support for it.

Luckily, installing a local version of Python is very easy. Here are the few simple steps required to install the latest and greatest Python and run your CGI scripts with it (I’m installing version 2.5.2 in this example).

Access your account with SSH and in the home directory execute:

wget http://www.python.org/ftp/python/2.5.2/Python-2.5.2.tgz
tar xvzf Python-2.5.2.tgz

This downloads and unzips the Python 2.5.2 source distribution. Now install Python locally to your home directory, executing:

cd Python-2.5.2
./configure -prefix=/home/username/python252 --enable-unicode=ucs4
make
make install

Replace username/python252 with your username on the host’s server and the target directory you want to install into. This operation will take a couple of minutes, depending on your server’s speed. It fully configures, compiles and installs Python from sources.

The next step is making the Python you’ve just installed the default Python in your shell. Open ~/.bashrc [1] and add this line at the end:

export PATH=/home/username/python252/bin:$PATH

Save and close the file. New bash shells will now have Python 2.5.2 respond to python. To make it happen in the current shell, type bash, and then python -V to see the new version.

Now, it is important to modify all your Python scripts (including CGI ones) to be executed with your private Python. Modify the shebang line at the top of the scripts to point to it:

#!/home/username/python252/bin/python

That’s about it ! Your Python CGI scripts will now run with Python 2.5.2

Since you’ve made Python 2.5.2 the default in your shell, you can now easily install new Python modules into its site-packages and use them in your scripts. Simply download the modules with wget and install them with python setup.py install. easy_install will work too, once you install it.

P.S. I expect this method, perhaps with minor modifications, to work for other providers as well, and not only Bluehost.

http://eli.thegreenplace.net/wp-content/uploads/hline.jpg
[1] Assuming bash is your shell. For other shells, adapt the example accordingly.

Related posts:

  1. Deploying TurboGears applications on shared hosting (Bluehost)
  2. Creating Python extension modules in C
  3. Setting up an initialization file for CLISP on Windows
  4. Some insights on Linux on the EEE
  5. Local execution of Python CGI scripts

5 Responses to “Installing Python 2.5 on Bluehost”

  1. AshNo Gravatar Says:

    Hey. I’m trying really hard to get this to work and am stuck.

    I did exactly what you said except that I replaced the folder name in the prefix with ‘$HOME’. Did everything else EXACTLY the same. I can see a /bin in the home folder and it has something called python2.6* in it. I edited the .bashrc to have ‘export PATH=\home\bin\:$PATH, saved it, and refreshed the shell.

    I’ve done this a number of times now and tried everything and it still keeps showing me the pre-installed version of python. Please help me out here…

  2. elibenNo Gravatar Says:

    @Ash,

    Maybe your export line is wrong – look at my example, it must contain the path to Python’s bin directory, not just \home\dir.

  3. DanNo Gravatar Says:

    Sorry im total newb, everything worked great until i had to adapt the bash instructions for osx terminal. Any tips?

  4. DaveNo Gravatar Says:

    Thanks this worked great.

  5. NateNo Gravatar Says:

    Wow this worked like a charm. Python 2.6.4 up and running like a champ! Thanks!