2013-03-03

Installing Python with Pythonbrew

This is the third in a series about installing and managing multiple versions of Pythion on a linux host. The main article which describes why this is necessary for development and testing, or to upgrade back-level os-provided versions is here.


Pythonbrew makes installation and management of multiple Python versions within the local user account easy.   It has a few issues:
  • I've found that it can fail to build some versions of Python.   Working around this involves giving it more specific Python version names, or by going back and making sure all the host libraries are properly installed.
  • It requires at least Python 2.6 to use - so if you're stuck with an older version (say, 2.4 on RHEL 5) to start you'll need to first install something more current using another method.  This results in two different python install methods which is confusing.
Nonetheless, this is probably the best solution if you're running a modern python version for your OS, and can't install the versions you need via the Package Manager.


The installation steps:

  1. Install dependencies - here's a practical minimum subset
    • On Debian/Ubuntu v12.04:
      • $ sudo apt-get install build-essential
      • $ sudo apt-get install tk-dev
      • $ sudo apt-get install libncursesw5-dev
      • $ sudo apt-get install libgdm-dev
      • $ sudo apt-get install libreadline-dev
      • $ sudo apt-get install libbz2-dev
      • $ sudo apt-get install libsqlite3-dev
      • $ sudo apt-get install libssl-dev 
      • $ sudo apt-get install libc6-dev (should already be in)
      • $ sudo apt-get install dpkg-dev (should already be in)
      • $ sudo apt-get install zlib1g-dev (should already be in)
      • if on 64-bit: $ sudo ln -s /lib/x86_64-linux-gnu/libz.so.l /lib/libz.so
    • On Redhat: 
      • $ sudo yum install readline-devel
  1. Install Pythonbrew:
    • $ curl -kL http://xrl.us/pythonbrewinstall | bash
  2. Update Environment
    • Add to .bashrc & run:
      • [[ -s $HOME/.pythonbrew/etc/bashrc ]] && source $HOME/.pythonbrew/etc/bashrc 
  3. Create a directory to keep build logs
    • $ mkdir ~/.pythonbrew/log_archive
    • After each build:
      • $ mv ~/.pythonbrew/log/build.log ~/.pythonbrew/archive_log/build-x.x.x.log
      • $ mv ~/.pythonbrew/log/x.x.x.log ~/.pythonbrew/archive_log/output-x.x.x.log
  4. Install Python Versions:
    • $ pythonbrew install 2.7.2 &> 2.7.2.log
    • $ pythonbrew install 2.6.8 &> 2.7.2.log
    • $ pythonbrew install 3.3.0 &> 2.7.2.log
    • After each build check your stdout & stderr in *.log, as well as the build log. You should definitely check the build_log for:
      • confirmation that setuptools and pip have been installed successfully
      • Look for "Failed to find the necessary bits to build these modules" - and determine if you can live without it failed to include.

      Now, lets work it:

    • $ pythonbrew list
    • $ pythonbrew use Python-3.3.0 # change session to this Python
    • $ pythonbrew switch Python-3.3.0 # permanently change to this version
    • $ pythonbrew uninstall Python-3.3.0


    A few notes on specific version combinations:

    •  Python 2.6 on Ubuntu 12.04 - this combo is tricky.  This is more difficult than with a deadsnakes PPA and apt-get install, but easier than with compiling from source.  Pythonbrew will build a working Python2.6 - but unless you follow the install-dependency step above, it'll be missing so many dependencies that it can't even install setuptools.

    Additional links to check out:


    • The project lives on github here, and has very good documentation.
    • suvashthapaliya.com/blog/2012/01/sandboxed-python-virtual-environments/

    8 comments:

    1. All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates…
      Regards
      Aamala
      SEO Training in Chennai

      ReplyDelete