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. Installing Python 2.7 on Ubuntu
  2. Deploying TurboGears applications on shared hosting (Bluehost)
  3. Bluehost – I’m watching you
  4. Some insights on Linux on the EEE
  5. Creating Python extension modules in C

7 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!

  6. @munselljNo Gravatar Says:

    Thanks for the helpful tutorial! I used it to setup 2.7.2 on my Bluehost account in order to run nodejs. Just thought I’d note a couple difference others may find helpful later:
    1) I had to use nano to modify my bashrc.
    cd ..
    nano .bashrc

    ctrl+x confirm save by typing ‘Y’ then enter, then enter again to confirm the file.

    2) After saving the changes I needed reload the bash for the changes to take effect.
    source .bashrc

    Thanks again!

    p.s. had some trouble leaving a comment, sorry if there’s a duplicate!

  7. tygernachNo Gravatar Says:

    Thanks for post! Worked for me fo python 2.7 too