The Nuclear Squid Musings on stuff and other things.

Mercurial fails with import error on Mac OS X

If you installed Mercurial, but it fails with the following error message when you try to use it:

Traceback (most recent call last):
  File "/usr/local/bin/hg", line 38, in <module>
    mercurial.dispatch.run()
  File "/Library/Python/2.7/site-packages/mercurial/dispatch.py", line 28, in run
    sys.exit((dispatch(request(sys.argv[1:])) or 0) & 255)
  File "/Library/Python/2.7/site-packages/mercurial/dispatch.py", line 41, in dispatch
    req.ui = uimod.ui()
  File "/Library/Python/2.7/site-packages/mercurial/ui.py", line 45, in __init__
    for f in scmutil.rcpath():
  File "/Library/Python/2.7/site-packages/mercurial/scmutil.py", line 464, in rcpath
    _rcpath = osrcpath()
  File "/Library/Python/2.7/site-packages/mercurial/scmutil.py", line 436, in osrcpath
    path = systemrcpath()
  File "/Library/Python/2.7/site-packages/mercurial/scmutil.py", line 489, in systemrcpath
    path.extend(rcfiles(os.path.join(p, root)))
  File "/Library/Python/2.7/site-packages/mercurial/scmutil.py", line 474, in rcfiles
    for f, kind in osutil.listdir(rcdir)
  File "/Library/Python/2.7/site-packages/mercurial/demandimport.py", line 86, in __getattribute__
    self._load()
  File "/Library/Python/2.7/site-packages/mercurial/demandimport.py", line 58, in _load
    mod = _origimport(head, globals, locals)
ImportError: dlopen(/Library/Python/2.7/site-packages/mercurial/osutil.so, 2): no suitable image found.  Did find:
    /Library/Python/2.7/site-packages/mercurial/osutil.so: mach-o, but wrong architecture

Then your Python most likely runs in 32-bit mode. To force Python to run in 64-bit mode, run this command:

defaults write com.apple.versioner.python Prefer-32-Bit -bool no