Skip to content

Instantly share code, notes, and snippets.

@BigglesZX
Created January 14, 2012 10:49
Show Gist options
  • Select an option

  • Save BigglesZX/1610950 to your computer and use it in GitHub Desktop.

Select an option

Save BigglesZX/1610950 to your computer and use it in GitHub Desktop.
Installing a custom version of Python on Dreamhost

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
@aivoric
Copy link
Copy Markdown

aivoric commented Nov 3, 2013

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

@jowr
Copy link
Copy Markdown

jowr commented May 14, 2014

Hi and thanks for sharing. I forked and updated some minor things. feel free to update your code.

@SoulCA
Copy link
Copy Markdown

SoulCA commented May 20, 2014

great tutorial/guide. Quick question, what is the path to python that should be the first line of each file?

@BigglesZX
Copy link
Copy Markdown
Author

@SoulCA – using the paths from the listed example it would be /home/biggleszx/python/bin/python

Sorry for the late reply! GitHub doesn't notify gist comments :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment