Had the same problem with a VPS that can't be upgraded to Maverick (even the new LTS images aren't always made available on time). Marius' answer did the trick to get me started, but it should be expanded upon:
Add the PPA to your sources
If you're in my situation, the simple advice of running
add-apt-repository won't work for you. So let's do this the old-fashioned way:
Open the file
/etc/apt/sources.list (you need root privileges; if you're on the shell, this probably means running
sudo vim /etc/apt/sources.list).
Go all the way to the bottom of the file (if using
vim, switch to insert mode by pressing
i) and add the following lines:
deb http://ppa.launchpad.net/fkrull/deadsnakes/ubuntu lucid main
deb-src http://ppa.launchpad.net/fkrull/deadsnakes/ubuntu lucid main
Save and exit (in
:wq) and go back to a shell.
Enter the following (you can find the correct key at the PPA; it's the part after the slash in the "technical details" -- make sure you got the right one):
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DB82666C
Now enter the following to update your source list:
sudo apt-get update
Install and set up Python 2.7
Open up a shell on your server and enter the following:
sudo apt-get install python2.7 python2.7-dev
easy_install working, get the
distribute bootscrap script:
curl -O http://python-distribute.org/distribute_setup.py
Finally, you want
virtualenv working if you plan to do anything serious:
pip-2.7 install virtualenv
Setting up a virtualenv
Create the folder for your new environment and open it:
mkdir my_env && cd my_env
Create the virtual environment itself (the dot indicates the current directory is the location of the environment, replace it with the correct path if you skipped the previous step):
virtualenv --no-site-packages --python=python2.7 .
Activate the environment. You'll notice the shell prompt changes to reflect the active environment:
Whatever you do in this shell now will use the scripts in the virtual environment's
bin folder and that environment's Python packages. Keep in mind the option
--no-site-packages means you're starting with the minimal set of packages (including
pip, however), so you need to install all packages you'll need.
When you're done, deactivate the environment (this is a command recognized by the active environment):
You can also install packages into the virtual environment by passing the
-E option to
pip install some-package -E /path/to/virtual/environment to install
some-package to the virtual environment on the given path). Keep in mind you'll have several different versions of
pip corresponding to the different Python versions installed.
It's a good idea to use
pip-2.7 if you want to install packages for Python 2.7 when working outside a virtual environment (the
--python=python2.7 option we passed to
virtualenv means the virtual environment will use the Python 2.7 versions of the tools it provides, so you don't have to worry about that).