14

Installing Mercurial on Mac OS X 10.6 Snow Leopard

I installed Mercurial 1.3.1 on Mac OS X 10.6 Snow Leopard from source using the following:

cd ~/src
curl -O https://www.mercurial-scm.org/release/mercurial-1.3.1.tar.gz
tar -xzvf mercurial-1.3.1.tar.gz
cd mercurial-1.3.1
make all
sudo make install

This installs the site-packages files for Mercurial in /usr/local/lib/python2.6/site-packages/. I know that installing Mercurial from the Mac Disk Image will install the files into /Library/Python/2.6/site-packages/, which is the site-packages directory for the Mac OS X default Python install.

I have Python 2.6.2+ installed as a Framework with its site-packages directory in:

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages

With Mercurial installed this way, I have to issue:

PYTHONPATH=/usr/local/lib/python2.6/site-packages:"${PYTHONPATH}"

in order to get Mercurial to work.

Questions

  • How can I install Mercurial from source with the site-packages in a different directory?
  • Is there an advantage or disadvantage to having the site-packages in the current location? Would it be better in one of the Python site-package directories that already exist?
  • Do I need to be concerned about virtualenv working correctly since I have modified PYTHONPATH (or any other conflicts for that matter)?

Reasons for Installing from Source

Dan Benjamin of Hivelogic provides the benefits of and instructions for installing Mercurial from source in his article Installing Mercurial on Snow Leopard.

1
  • Macports is an option; however, in this case, I'm interested in installing Mercurial from source. It seems natural to me to use Mercurial to keep itself up to date, although you have to solve the chicken and egg problem, which is what led to my question. Dec 30, 2009 at 13:41

5 Answers 5

13

Why need to use macports? python easy_install is the easiest way and error free:

easy_install -U mercurial

It's just a simple gold bullet, all the time.

1
  • Installing via macports or easy_install are both options. However, my questions are regarding installing Mecurial from source. Apr 2, 2010 at 13:17
8

Especially since you have Python 2.6 available you can do something like python setup.py install --user, which will install Mercurial with ~/.local as prefix. You don't have to change the PYTHONPATH for this but only add ~/.local/bin to your PATH.

Regarding advantages and disadvantages: That all depends on what your PYTHONPATH in general looks like since modifying it will naturally modify the load order of packages (which becomes relevant if you have one version of Mercurial installed with one prefix and another with a different prefix). In general, I try to put all custom packages into a certain site-packages folder (say /usr/local/lib/python2.6/site-packages). Again: If you are the only person who will use those libs, the --user flag provided by Python 2.6's distutils makes something like this pretty easy (with adding ~/.local to the default search path for modules).

virtualenv should work just fine as long you your PYTHONPATH is used consistently.

8

Install mercurial - or any Python package in general - into your user home directory. Thus you can access them from any Python (of same version) or any virtualenv. See PEP 370 for details.

$ cd mercurial-x.y.z/
$ python2.6 setup.py install --user
$ ~/.local/bin/hg
...

But why do you want to build mercurial manually? I use macports.

$ sudo port install mercurial
$ which hg
/opt/local/bin/hg

Update: Nowadays, I simply use PyPM to install mercurial into ~/.local/bin/hg.

5

as suggested by Sridhar, macports works fine on multiple architecture and versions of MacOsX + allows updates and more:

$ port variants mercurial
mercurial has the variants:
   bash_completion: Completion support for bash
   zsh_completion: Install mercurial zsh completion file
$

so that you may use:

$ sudo port install mercurial +bash_completion
--->  Computing dependencies for mercurial
--->  Fetching mercurial
--->  Attempting to fetch mercurial-1.3.1.tar.gz from http://arn.se.distfiles.macports.org/python
--->  Attempting to fetch mercurial-1.3.1.tar.gz from http://www.selenic.com/mercurial/release/
--->  Verifying checksum(s) for mercurial
--->  Extracting mercurial
--->  Configuring mercurial
--->  Building mercurial
--->  Staging mercurial into destroot
--->  Installing mercurial @1.3.1_0+bash_completion
--->  Activating mercurial @1.3.1_0+bash_completion
--->  Cleaning mercurial
$
1

All those answers look complicated to the average mac OS X users, because they are specific to other install platforms. As of now the Mercurial website offers an installer package (compressed as a zip file).

1
  • 2
    Got a link for us? (Silly that SO won't let my comment be "Link?" (too short.))
    – Olie
    Jun 20, 2010 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.