Installing Python 2.5 on Bluehost
October 20th, 2008 at 6:52 pmBluehost 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.

| [1] | Assuming bash is your shell. For other shells, adapt the example accordingly. |
Related posts:

August 13th, 2009 at 12:22
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…
August 14th, 2009 at 06:54
@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.
August 23rd, 2009 at 08:39
Sorry im total newb, everything worked great until i had to adapt the bash instructions for osx terminal. Any tips?
October 25th, 2009 at 03:43
Thanks this worked great.
December 3rd, 2009 at 23:00
Wow this worked like a charm. Python 2.6.4 up and running like a champ! Thanks!
December 10th, 2011 at 18:13
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 .bashrcThanks again!
p.s. had some trouble leaving a comment, sorry if there’s a duplicate!
April 26th, 2012 at 10:27
Thanks for post! Worked for me fo python 2.7 too