14 comments

[ 2.9 ms ] story [ 46.4 ms ] thread
How well does it work? I friggin' love RVM, so a Python version of that would be most welcome!
I'm on OS X Lion and I had to --force the installs but they appear to be working correctly. Very simple and use to use, though not as smart as rvm about version numbers (for example, typing 2.7 won't automatically switch to your 2.7.2 install -- you have to explicitly use 2.7.2). Also, no Jython/IronPython/PyPy.
I was considering tackling this issue myself. I love perlbrew, and I was looking for something similar in the Python world and virtualenv didn't cut it.
Forgive a newbie question: what about virtualenv doesn't cut it?
The only thing that virtualenv does is isolate a set of libraries to use with the default system python. If you have Python 2.6 installed, but want to use Python 2.7, you're responsible for setting it up yourself.

On the other hand, perlbrew allows you to manage completely separate builds of perl, and the associated tools like cpan/cpanminus will install to whatever the currently selected Perl is.

For example, my perlbrew at work looks like this:

  % tree -L 2 ~/perl5/perlbrew
  ~/perl5/perlbrew/
  |-- Conf.pm
  |-- bin
  |   |-- cpanm
  |   `-- perlbrew
  |-- build
  |   |-- perl-5.12.3
  |   `-- perl-5.14.1
  |-- build.log
  |-- dists
  |   |-- perl-5.12.3.tar.gz
  |   `-- perl-5.14.1.tar.gz
  |-- etc
  |   |-- bashrc
  |   `-- cshrc
  `-- perls
      |-- current -> perl-5.12.3
      |-- perl-5.12.3
      `-- perl-5.14.1
You source the appropriate ~/perl5/perlbrew/etc/{bash,csh}rc for your shell, which creates a shell function called perlbrew.

  % type perlbrew
  perlbrew is a shell function
  % perlbrew       
  Usage:
          perlbrew <command> [options] [arguments]
  
          Commonly used commands:
              init           Initialize perlbrew environment.
              install        Install perl
              list           List installed perls
              use            Use the specified perl in current shell
              switch         Permanently use the specified perl as default
              mirror         Pick a preferred mirror site
              off            Permanently turn off perlbrew
              version        Display version
              help           Read more detailed instructions
  
          Examples:
              perlbrew install perl-5.12.3
              perlbrew install perl-5.13.6
  
              perlbrew list
  
              perlbrew use perl-5.13.6
              perlbrew switch perl-5.12.3
  
              perlbrew switch /path/to/special/perl
              perlbrew switch /path/to/special/perl special-perl
              # later
  % perlbrew list                                                                                                              
  * perl-5.12.3
    perl-5.14.1
    /usr/local/bin/perl (5.8.8)
    /usr/bin/perl (5.8.8)
  % perlbrew version
  ~/perl5/perlbrew/bin/perlbrew  - App::perlbrew/0.19
  % perlbrew available
    perl-5.15.1
  i perl-5.14.1
    perl-5.12.4
    perl-5.10.1
    perl-5.8.9
    perl-5.6.2
    perl5.005_04
    perl5.004_05
    perl5.003_07
  % perlbrew install perl-5.10.1
  Attempting to load conf from ~/perl5/perlbrew/Conf.pm
  Fetching perl-5.10.1 as ~/perl5/perlbrew/dists/perl-5.10.1.tar.gz
  Installing perl-5.10.1 into ~/perl5/perlbrew/perls/perl-5.10.1
  This could take a while. You can run the following command on another shell
  to track the status:
  
    tail -f ~/perl5/perlbrew/build.log
  
  (cd ~/perl5/perlbrew/build; tar xzf ~/perl5/perlbrew/dists/perl-5.10.1.tar.gz;
    cd ~/perl5/perlbrew/build/perl-5.10.1;rm -f config.sh Policy.sh;patchperl;
    sh Configure -de '-Dprefix=~/perl5/perlbrew/perls/perl-5.10.1';make ;make
    test_harness && make install) >> '~/perl5/perlbrew/build.log' 2>&1
  Installed perl-5.10.1 as perl-5.10.1 successfully. Run the following command
  to switch to it.
  
    perlbrew switch perl-5.10.1
Just curious, but how does this differ from Virtualenv?
Likewise curious. Seems like that should be addressed in the README.
Pythonbrew installs multiple versions of python and manages your path so you can switch which ones are active. I have only played around with it a bit, but the combination of Pythonbrew and Virtualenv should be approximately the same as rvm for ruby.
hmm... what about many virtual envs each with their own pythons?
This is what was missing from virtualenv (in comparison to RVM). I can't wait to see how it progresses and if somehow this and virtualenv merge at some point.
I'm familiar with these techniques from RVM, but for Python I've been content explicitly calling python2.5, python2.7, or python3.

What else does this tool offer?

It essentially just provides a way to have multiple python installations with less configuration on your part. You can just 'pythonbrew use 2.7.2' and 'pip install twisted' instead of having multiple pip-2., virtualenv-2., ipython-2.*, etc. (I'm assuming you have a version-specific script for each version of python)
To those asking how this differs from virtualenv: it's meant to compliment it. When you setup a new virtualenv, you can provide it with a specific python interpreter to use (2.6, 2.7, 3.2, pypy, etc). Traditionally, you as a developer had to manually manage all of these base python installations in various places throughout your system, either from your distro's package manager or compiling from source.

Pythonbrew automates this for you, making it dead simple to have several python variations living harmoniously on your system at the same time. From what I understand it plus virtualenv are now the equivalent to Ruby's rvm in features and ease-of-use (although you'll probably also want to grab virtualenvwrapper to make your life even easier).

It also provides a quick, scriptable way to test your code against multiple versions of python, which is quite handy for library authors.