Dreamhost supplies a fairly old version of Python in their shared hosting environments. It recently became necessary for me to use a newer version, and since this involved a bit of juggling, I thought I’d detail the steps here.
The end result of this process is being able to run a current version of Python from your shared hosting user’s shell. It requires compiling, installing and running Python from your home directory rather than the system bin directories.
1. Create a helpful working directory
I chose to install all Python-related stuff in a python/ directory under my user’s home directory.
$ mkdir ~/python
$ cd ~/python
2. Download an up-to-date version of the Python source
At the time of writing this was 2.7.2. You may wish to use a different version.
$ wget http://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz
$ tar -xzf Python-2.7.2.tgz
$ cd Python-2.7.2
3. Establish the full path to your new Python working directory
When running the Python configure script, we need to supply a prefix that tells the compiler to set everything up locally. We’ll be running Python out of ~/python and we need to know full path to that directory.
$ pwd
/home/biggleszx/python/Python-2.7.2
Keep a mental note of this.
4. Run the Python configure script
We’ll supply the path to our python dir as established above, thus:
$ ./configure --prefix=/home/biggleszx/python
This sets everything up to install locally. You will see lots of technical output, but hopefully everything will progress OK (the Dreamhost environment has just about everything we need to install Python). If your project requires certain special Python features, you may need to install additional dependencies.
5. make, make install
Once ./configure has run, we can perform the actual compilation.
$ make
This might take a while. Once it’s done:
$ make install
This installs the compiled Python binaries.
6. Reconfigure your environment to use the newly created local Python binaries
If you check your Python version now, you should still see the older Dreamhost-supplied system version:
$ python --version
Hi James,
Just wanted to say that I found this REALLY useful! :-)
Would appreciate if you could write another one on how to install a python-mysql connector on Dreamhost.
Thank you!
~Aivoric