ROOT Installation
Introduction
The following instructions are for those trying to install ROOT on OS X 10.7 Lion with python bindings (PyROOT) and numpy, scipy, and matplotlib. For example, in a python script, one can import (a sample from one of my scripts)…
# Root imports from ROOT import TH1F, TFile, THStack, TF1, TCanvas, TLegend from ROOT import kRed, kBlue, kWhite from ROOT import gStyle, gPad # SciPy and Numpy import scipy as sp import numpy as np import matplotlib as plt
Altogether, it’s a highly flexible environment for scientific computing.
Note: The below instructions are only valid if you have XCode installed (see my post on Mac Setup, Part 1)
Installing ROOT with Python Support
We will take the following route:
- Install an appropriate version of Python
- Install a fortran compiler (gfortran)
- Create a directory for our root installation
- Download the most recent version of the ROOT source and unpack in the install directory
- Set the envionrment variables required for installation
- Configure, make and install ROOT with python support
- Set remaining enviornmental variables
- Test and enjoy your new computing environment
Prerequisites
It is assumed that you have XCode installed. If not, please see my earlier post.
Python
One of the trickiest parts of the installation was finding a compatable version of python. There were three issues.
- I couldn't find legacy installers for Python 2.6 in Lion (2.7 and 3.1 were available from the Python.org website).
- The build type of Python and ROOT must be identical (both must be either 32 bit or 64 bit).
- NumPy, SciPy, and matplotlib must be compatible with the installed Python version.
I wanted to compile and install a 64 bit ROOT installation. The 2.7 Python installer from Python.org installs both 32 and 64 bit versions of Python (e.g. python2.7 and python2.7-32). One can compile ROOT with Python support using the standard Python.org 2.7 distribution with minimal effort. Everything will work well, but you will not have access to numpy, scipy, and matplotlib. These packages must be installed separately.
Most of my problems arose because of scipy and numpy. Building numpy from source requires Python 2.4, 2.5, or 2.6, but not 2.7. The package installer for 2.7 is only for 32 bit Python. I was not able to find a compatible version of Scipy and Numpy from the Scipy.org web site that worked with my 64 bit tandem install of python 2.7 and ROOT.
Luckily, the Enthought Python Distribution (EPD) provided a 64bit, Python 2.7 framework install that included numpy and scipy. The EPD 64bit distribution is, however, only free for academics. EPD Free (free for anyone) is so far 32 bit only for Apple and Windows platforms.
The 64 bit EPD Framework install is located at /Library/Frameworks/EPD64.framework/Versions/7.1/. Both 32 and 64 bit EPD distributions can be concurrently installed. The 32 bit version is located at /Library/Frameworks/Python.framework/Versions/7.1/.
Fortran Compiler
Root requires a fortran compiler. This is neither provided by a stock install of 10.7 nor XCode. There are three sources for free Fortran compilers online, and they are all uncompatable. Install only one version. I have used the version provided by AT&T's R research page. Follow their instructions.
Download ROOT
Create a directory to store the ROOT installation binaries, libraries, and other files.
sudo mkdir /usr/local/root
Download the latest ROOT source code from their download page. For Lion, the latest development version, as of early September 2011, was the 5.30/01 patch. The professional version 5.30/00 compiled with problems. Recently, the production (Pro) version has been updated to 5.30/02 and I now recommend that version.
After your download, unpack the files in your ROOT directory, i.e.
gzip -dc root_<version>.source.tar.gz | tar -xf -
Environment Variables and other Pre-compilation Steps
Two types of installation are possible:
- Location independent version: Installation in an arbitrary and movable location as pointed to by a set of environment variables.
- Location dependent version: Installation in a fixed directory selected during configuration through the --prefix flag.
I chose the location independent version. Before configuring your installation through ./configure, set your environment variables. Because we are compiling with python support, you must point to the location of the python version you want married to ROOT. For me, this was the 64 bit Enthought distribution located at /Library/Frameworks/EPD64.framework/Versions/Current/.
The required environment variables needed for ./configure for a location independent install with python support are listed below. Please keep in mind that these are specific to my installation of Python and the location I wanted my ROOT distribution to reside.
export ROOTSYS=/usr/local/root/5.30.01 export PYTHONDIR=/Library/Frameworks/EPD64.framework/Versions/Current/
Configuration and Installation
From your ROOT folder, run the configuration script for your OS X 64 bit system.
./configure macosx64
Python support is included by default. After a successful configuration, compile through make
sudo make -j4
The -j4 flag indicates my system has four cores. Compilation will go much faster when you can simultaneously run four instances of your fortran or c compiler. There is no sudo make install. We have chosen a location independent install. Your binaries will be located under $ROOTSYS/bin. make install moves your files to a --prefix path specified in your ./configure. We did not specify such a path.
During my process of discovering how to install ROOT, I messed up my configuration several times. Even after a make clean I was getting errors like
No rule to make target `XrdOucFactoryBonjour.hh', needed by > > > `../../obj/XrdOucBonjour.o'. Stop.
on my next build. These errors were cleared by issuing
make distclean-xrootd make all-xrootd
after my make clean and before ./configure macosx64.
Final Steps
Before running ROOT or important ROOT objects into python, you need to set a few more environment variables. From my .zshrc (instructions are identical for .bashrc),
# ROOT Data Analysis Framework #export ROOTSYS=/usr/local/root/5.30.01 export ROOTSYS=/usr/local/root/current/ export LD_LIBRARY_PATH=$ROOTSYS/lib:$LD_LIBRARY_PATH export DYLD_LIBRARY_PATH=$ROOTSYS/lib:$DYLD_LIBRARY_PATH export SHLIB_PATH=$ROOTSYS/lib:$SHLIB_PATH export LIBPATH=$ROOTSYS/lib:$LIBPATH export MANPATH=$ROOTSYS/man:$MANPATH export PYTHONPATH=$ROOTSYS/bindings/pyroot:$PYTHONPATH export PYTHONPATH=$ROOTSYS/lib:$PYTHONPATH export PYTHONDIR=/Library/Frameworks/EPD64.framework/Versions/Current/
That should be it. ROOT can be run through the terminal
root
To test pyroot, launch the 64bit Enthought Python executable /Library/Frameworks/EPD64.framework/Versions/Current/bin/python (I've created a symbolic link to the binary called epython64 and placed the symbolic link in ~/bin) and import ROOT
➜ ~ epython64 Enthought Python Distribution -- www.enthought.com Version: 7.1-2 (64-bit) Python 2.7.2 |EPD 7.1-2 (64-bit)| (default, Jul 27 2011, 14:50:45) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "packages", "demo" or "enthought" for more information. >>> import ROOT >>>
No errors are reported. The install was a success.