Fixing Bazaar for Mac OS X

When upgrading to Lion, if you try to run bzr, you’ll get an error:

$ bzr whoami
bzr: ERROR: Couldn't import bzrlib and dependencies.
Please check the directory containing bzrlib is on your PYTHONPATH.

Traceback (most recent call last):
  File "/usr/local/bin/bzr", line 102, in <module>
  import bzrlib
ImportError: No module named bzrlib

It seems to be caused by Lion’s switch to python 2.7 as default, while bazaar installs on python 2.6.

Edit the file /usr/local/bin/bzr (with sudo) and complete the first line:

#!/usr/bin/python

to

#!/usr/bin/python2.6

and save, that should do the trick.

$ bzr whoami
Name Surname <name@example.com>