﻿{"id":1712,"date":"2018-06-29T17:11:17","date_gmt":"2018-06-29T09:11:17","guid":{"rendered":"http:\/\/nick.txtcc.com\/?p=1712"},"modified":"2018-06-29T17:11:17","modified_gmt":"2018-06-29T09:11:17","slug":"upgrade-to-python-2-7-9-on-ubuntu-14-04-lts","status":"publish","type":"post","link":"http:\/\/nick.txtcc.com\/index.php\/linux\/1712","title":{"rendered":"Upgrade to Python 2.7.9 on Ubuntu 14.04 LTS"},"content":{"rendered":"<article>\n<div id=\"article_content\" class=\"article_content clearfix csdn-tracking-statistics\" data-pid=\"blog\" data-mod=\"popu_307\" data-dsm=\"post\">\n<div class=\"htmledit_views\">\n<h2 class=\"entry-title\">Upgrade to Python 2.7.9 on Ubuntu 14.04 LTS, and make your own .deb package for deployment<\/h2>\nNeed to run your web app with Python 2.7.9, but server environment uses Ubuntu 14.04 LTS? Don\u2019t replace Python, leverage VirtualEnv instead!\n<div class=\"hentry-sharing\"><\/div>\nApril 5, 2015\n<div class=\"hentry-content\">\n\nI 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.\n\n<strong>IMPORTANT<\/strong>\u00a0This procedure isn\u2019t complete as I had to shift focus elsewhere. I might rework this article to adjust what\u2019s missing.\n\nWhile I understand that Ubuntu 14.04\u00a0<a href=\"http:\/\/askubuntu.com\/questions\/559036\/when-will-the-python-2-7-9-upgrades-be-available-from-apt-get-for-14-04lts#answer-560159\" target=\"_blank\" rel=\"nofollow\">will<\/a>\u00a0<a href=\"http:\/\/serverfault.com\/questions\/669859\/how-can-i-upgrade-python-to-2-7-9-on-ubuntu-14-4\" target=\"_blank\" rel=\"nofollow\">remain<\/a>\u00a0using\u00a0<em>Python 2.7.6<\/em>\u00a0internally, applications we run can be configured to use another python environment. Its what virtualenv is all about after all, isn\u2019t it.\n\nThis post attempts to install, and make an installable\u00a0<em>.deb<\/em>\u00a0package of\u00a0<strong>Python 2.7.9<\/strong>\u00a0and is meant to be used by web applications without touching the system\u2019s python runtime.\n<h2><a name=\"t1\"><\/a>Why not replacing internal Python version?<\/h2>\nThe reason is simple. If you replace internal Python version, other softwares within the OS will have broken dependencies.\n\nI 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.\n\nIf you see procedures that shows you to replace telling you to use\u00a0<code>update-alternatives<\/code>\u00a0to replace python, don\u2019t do it! Go instead learn how to run your own Python version in VirtualEnv.\n<h2><a name=\"t2\"><\/a>Procedure<\/h2>\n<ol>\n    <li>Install build dependencies\n\nThose were the ones I ran last before a successful build on\u00a0<strong>Ubuntu 14.04 LTS<\/strong>, if you aren\u2019t using the same distribution, you might get a different list.\n<pre><code class=\"hljs\"><\/code><\/pre>\n<pre><code class=\"language-cpp hljs\">  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<\/code><\/pre>\n<\/li>\n    <li>Get Python sources and compile\n<pre><code class=\"hljs\"><\/code><\/pre>\n<ol class=\"hljs-ln\">\n    <li>\n<div class=\"hljs-ln-numbers\"><\/div>\n<div class=\"hljs-ln-code\">\n<div class=\"hljs-ln-line\">wget https:<span class=\"hljs-comment\">\/\/www.python.org\/ftp\/python\/2.7.9\/Python-2.7.9.tgz<\/span><\/div>\n<\/div><\/li>\n    <li>\n<div class=\"hljs-ln-numbers\"><\/div>\n<div class=\"hljs-ln-code\">\n<div class=\"hljs-ln-line\">tar xfz Python<span class=\"hljs-number\">-2.7<\/span>\n<span class=\"hljs-number\">.9<\/span>.tgz<\/div>\n<\/div><\/li>\n    <li>\n<div class=\"hljs-ln-numbers\"><\/div>\n<div class=\"hljs-ln-code\">\n<div class=\"hljs-ln-line\">cd Python<span class=\"hljs-number\">-2.7<\/span>\n<span class=\"hljs-number\">.9<\/span>\/<\/div>\n<\/div><\/li>\n    <li>\n<div class=\"hljs-ln-numbers\"><\/div>\n<div class=\"hljs-ln-code\">\n<div class=\"hljs-ln-line\">.\/configure &#8211;prefix \/usr\/local\/lib\/python2<span class=\"hljs-number\">.7<\/span>\n<span class=\"hljs-number\">.9<\/span> &#8211;enable-ipv6<\/div>\n<\/div><\/li>\n    <li>\n<div class=\"hljs-ln-numbers\"><\/div>\n<div class=\"hljs-ln-code\">\n<div class=\"hljs-ln-line\">make<\/div>\n<\/div><\/li>\n    <li>\n<div class=\"hljs-ln-numbers\"><\/div>\n<div class=\"hljs-ln-code\">\n<div class=\"hljs-ln-line\">make install<\/div>\n<\/div><\/li>\n<\/ol>\n<\/li>\n    <li>Test if the version works\n<pre><code class=\"hljs\"><\/code><\/pre>\n<ol class=\"hljs-ln\">\n    <li>\n<div class=\"hljs-ln-numbers\"><\/div>\n<div class=\"hljs-ln-code\">\n<div class=\"hljs-ln-line\">\/usr\/local\/lib\/python2<span class=\"hljs-number\">.7<\/span>\n<span class=\"hljs-number\">.9<\/span>\/bin\/python -V<\/div>\n<\/div><\/li>\n    <li>\n<div class=\"hljs-ln-numbers\"><\/div>\n<div class=\"hljs-ln-code\">\n<div class=\"hljs-ln-line\">Python <span class=\"hljs-number\">2.7<\/span>\n<span class=\"hljs-number\">.9<\/span><\/div>\n<\/div><\/li>\n<\/ol>\n<\/li>\n    <li>Then prepare package through FPM\n<pre><code class=\"hljs\"><\/code><\/pre>\n<ol class=\"hljs-ln\">\n    <li>\n<div class=\"hljs-ln-numbers\"><\/div>\n<div class=\"hljs-ln-code\">\n<div class=\"hljs-ln-line\">apt-get install -y ruby-dev gcc<\/div>\n<\/div><\/li>\n    <li>\n<div class=\"hljs-ln-numbers\"><\/div>\n<div class=\"hljs-ln-code\">\n<div class=\"hljs-ln-line\">gem install fpm<\/div>\n<\/div><\/li>\n    <li>\n<div class=\"hljs-ln-numbers\"><\/div>\n<div class=\"hljs-ln-code\">\n<div class=\"hljs-ln-line\">&#8230;<\/div>\n<\/div><\/li>\n<\/ol>\n<\/li>\n<\/ol>\nIts basically about creating a .deb based on your new runtime setup. You can do that by using\u00a0<a href=\"https:\/\/github.com\/jordansissel\/fpm\" target=\"_blank\" rel=\"nofollow\">fpm<\/a>(\u201cFabulous Package Manager\u201d), I am\u00a0<a href=\"https:\/\/renoirboulanger.com\/blog\/2015\/02\/install-php5-memcached-pecl-extension-support-igbinary\/\" target=\"_blank\" rel=\"nofollow\">using this technique in a post I published recently about installing a PHP library<\/a>.\n<h2><a name=\"t3\"><\/a>Incomplete scratchpad<\/h2>\nBut that\u2019s as far as my notes goes for now. Sorry about that.\n<h3><a name=\"t4\"><\/a>Setuptools<\/h3>\nAs per recommended in\u00a0<a href=\"https:\/\/pypi.python.org\/pypi\/setuptools#unix-wget\" target=\"_blank\" rel=\"nofollow\">Setuptools instructions<\/a>, we can run\u00a0<code>easy_install<\/code>\u00a0through a\u00a0<code>wget<\/code>, like so;\n<pre><code class=\"hljs\"> <\/code><\/pre>\n<ol class=\"hljs-ln\">\n    <li>\n<div class=\"hljs-ln-numbers\"><\/div>\n<div class=\"hljs-ln-code\">\n<div class=\"hljs-ln-line\">wget https:<span class=\"hljs-comment\">\/\/bootstrap.pypa.io\/ez_setup.py -O &#8211; | \/usr\/local\/lib\/python2.7.9\/bin\/python<\/span><\/div>\n<\/div><\/li>\n    <li>\n<div class=\"hljs-ln-numbers\"><\/div>\n<div class=\"hljs-ln-code\">\n<div class=\"hljs-ln-line\">\/usr\/local\/lib\/python2<span class=\"hljs-number\">.7<\/span>\n<span class=\"hljs-number\">.9<\/span>\/bin\/easy_install pip<\/div>\n<\/div><\/li>\n    <li>\n<div class=\"hljs-ln-numbers\"><\/div>\n<div class=\"hljs-ln-code\">\n<div class=\"hljs-ln-line\">\/usr\/local\/lib\/python2<span class=\"hljs-number\">.7<\/span>\n<span class=\"hljs-number\">.9<\/span>\/bin\/pip install virtualenv<\/div>\n<\/div><\/li>\n<\/ol>\nThen, create symbolic links\n<pre><code class=\"hljs\"><\/code><\/pre>\n<ol class=\"hljs-ln\">\n    <li>\n<div class=\"hljs-ln-numbers\"><\/div>\n<div class=\"hljs-ln-code\">\n<div class=\"hljs-ln-line\">ln -s \/usr\/local\/lib\/python2<span class=\"hljs-number\">.7<\/span>\n<span class=\"hljs-number\">.9<\/span>\/bin\/easy_install \/usr\/bin\/easy_install<\/div>\n<\/div><\/li>\n    <li>\n<div class=\"hljs-ln-numbers\"><\/div>\n<div class=\"hljs-ln-code\">\n<div class=\"hljs-ln-line\">ln -s \/usr\/local\/lib\/python2<span class=\"hljs-number\">.7<\/span>\n<span class=\"hljs-number\">.9<\/span>\/bin\/pip \/usr\/bin\/pip<\/div>\n<\/div><\/li>\n<\/ol>\nYou can try if it worked\n<ol class=\"hljs-ln\">\n    <li>\n<div class=\"hljs-ln-numbers\"><\/div>\n<div class=\"hljs-ln-code\">\n<div class=\"hljs-ln-line\"><span class=\"hljs-selector-tag\">pip<\/span> <span class=\"hljs-selector-tag\">list<\/span><\/div>\n<\/div><\/li>\n    <li>\n<div class=\"hljs-ln-numbers\"><\/div>\n<div class=\"hljs-ln-code\">\n<div class=\"hljs-ln-line\"><span class=\"hljs-selector-tag\">pip<\/span> (6<span class=\"hljs-selector-class\">.0<\/span>\n<span class=\"hljs-selector-class\">.8<\/span>)<\/div>\n<\/div><\/li>\n    <li>\n<div class=\"hljs-ln-numbers\"><\/div>\n<div class=\"hljs-ln-code\">\n<div class=\"hljs-ln-line\"><span class=\"hljs-selector-tag\">setuptools<\/span> (14<span class=\"hljs-selector-class\">.3<\/span>)<\/div>\n<\/div><\/li>\n    <li>\n<div class=\"hljs-ln-numbers\"><\/div>\n<div class=\"hljs-ln-code\">\n<div class=\"hljs-ln-line\"><span class=\"hljs-selector-tag\">virtualenv<\/span> (12<span class=\"hljs-selector-class\">.0<\/span>\n<span class=\"hljs-selector-class\">.7<\/span>)<\/div>\n<\/div><\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n<\/article>\n<div class=\"article-bar-bottom\"><\/div>","protected":false},"excerpt":{"rendered":"<p>Upgrade to Python 2.7.9 on Ubuntu 14.04 LTS, and make your own .deb package for deployment Need to r&#46;&#46;&#46;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,274],"tags":[494,275],"class_list":["post-1712","post","type-post","status-publish","format-standard","hentry","category-linux","category-python","tag-2-7-9","tag-python-2"],"_links":{"self":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1712","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/comments?post=1712"}],"version-history":[{"count":1,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1712\/revisions"}],"predecessor-version":[{"id":1713,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/1712\/revisions\/1713"}],"wp:attachment":[{"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/media?parent=1712"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/categories?post=1712"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/tags?post=1712"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}