Upgrade to Python 2.7.9 on Ubuntu 14.04 LTS

Upgrade to Python 2..

Upgrade to Python 2.7.9 on Ubuntu 14.04 LTS, and make your own .deb package for deployment

Need to run your web app with Python 2.7.9, but server environment uses Ubuntu 14.04 LTS? Don’t replace Python, leverage VirtualEnv instead!

April 5, 2015

I had this post hanging in my drafts on how I attempted to install a valid Python 2.7.9 runtime environment on Ubuntu 14.04 and make my own .deb package for easy re-deployment.

IMPORTANT This procedure isn’t complete as I had to shift focus elsewhere. I might rework this article to adjust what’s missing.

While I understand that Ubuntu 14.04 will remain using Python 2.7.6 internally, applications we run can be configured to use another python environment. Its what virtualenv is all about after all, isn’t it.

This post attempts to install, and make an installable .deb package of Python 2.7.9 and is meant to be used by web applications without touching the system’s python runtime.

Why not replacing internal Python version?

The reason is simple. If you replace internal Python version, other softwares within the OS will have broken dependencies.

I realized this while I wanted to upgrade the version and breaking an hard dependency I have on Salt Stack. Since many components within a given Ubuntu version relies on Python, it could break anything else. This is why I stopped working on the idea of replacing internally, but instead to configure VirtualEnv to use another version instead.

If you see procedures that shows you to replace telling you to use update-alternatives to replace python, don’t do it! Go instead learn how to run your own Python version in VirtualEnv.

Procedure

  1. Install build dependencies

    Those were the ones I ran last before a successful build on Ubuntu 14.04 LTS, if you aren’t using the same distribution, you might get a different list.

      apt-get install -y gcc-multilib g++-multilib libffi-dev libffi6 libffi6-dbg python-crypto python-mox3 python-pil python-ply libssl-dev zlib1g-dev libbz2-dev libexpat1-dev libbluetooth-dev libgdbm-dev dpkg-dev quilt autotools-dev libreadline-dev libtinfo-dev libncursesw5-dev tk-dev blt-dev libssl-dev zlib1g-dev libbz2-dev libexpat1-dev libbluetooth-dev libsqlite3-dev libgpm2 mime-support netbase net-tools bzip2
  2. Get Python sources and compile
    1. wget https://www.python.org/ftp/python/2.7.9/Python-2.7.9.tgz
    2. tar xfz Python-2.7.9.tgz
    3. cd Python-2.7.9/
    4. ./configure –prefix /usr/local/lib/python2.7.9 –enable-ipv6
    5. make
    6. make install
  3. Test if the version works
    1. /usr/local/lib/python2.7.9/bin/python -V
    2. Python 2.7.9
  4. Then prepare package through FPM
    1. apt-get install -y ruby-dev gcc
    2. gem install fpm

Its basically about creating a .deb based on your new runtime setup. You can do that by using fpm(“Fabulous Package Manager”), I am using this technique in a post I published recently about installing a PHP library.

Incomplete scratchpad

But that’s as far as my notes goes for now. Sorry about that.

Setuptools

As per recommended in Setuptools instructions, we can run easy_install through a wget, like so;

 
  1. wget https://bootstrap.pypa.io/ez_setup.py -O – | /usr/local/lib/python2.7.9/bin/python
  2. /usr/local/lib/python2.7.9/bin/easy_install pip
  3. /usr/local/lib/python2.7.9/bin/pip install virtualenv

Then, create symbolic links

  1. ln -s /usr/local/lib/python2.7.9/bin/easy_install /usr/bin/easy_install
  2. ln -s /usr/local/lib/python2.7.9/bin/pip /usr/bin/pip

You can try if it worked

  1. pip list
  2. pip (6.0.8)
  3. setuptools (14.3)
  4. virtualenv (12.0.7)