Mac OS X Installation instructions

The installation of Python and the ROOT libraries consist of three steps:
1) Installing Python
2) Installing ROOT
3) Importing ROOT from Python (setting of environmental variables)

1 Installing Python 2.7:

Python is typically part of newer OS X installations. In that case you can skip this step. See 1.1 below for checking if you have a working python installation.
If you REALLY need to install python (and this is bad for the rest of the setup, as you will have to compile ROOT yourself, which in turn requires XCode!!!) you can find .dmg files here.

1.1 Testing your python installation

Open a terminal and type:
>> python --version
Python is installed if the output is similar to:
Python 2.7.12
Note: Logging out and in again may be required on OS X after installing Python.

2 Installing ROOT:

First download the ROOT source distribution (v5.34) from the ROOT download website. Scroll down to the OS X section in the Binaries section, and download the relevant file. Move the downloaded .tar.gz file to the folder where you want to install ROOT (We recommend to use your user directory). Now open a terminal and extract the content of the downloaded file, e.g.:
>> tar -zxvf root_v5.34.36.macosx64-10.9-clang60.tar.gz
(The file may have a slightly different name, adjust is accordingly).
In order to avoid setting up ROOT every time you want to use it, it is suggested to add the following line to the end of your file (in your user directory): "~/.bash_profile": "source /usr/local/root/bin/thisroot.sh".
This can be done in a smart one-liner way by executing:
>> printf "\nsource "`pwd`"/root/bin/thisroot.sh\n" >> ~/.bash_profile
In this way ROOT can be opened from anywhere just typing ">> root" in the terminal.
If this for some reason doesn't work, then try to install ROOT by compiling it yourself (Note: This takes some time for your computer!), as described here.

Note (if a terminal is new to you): Commands are executed by typing them into the terminal and pressing enter. You can always check in which folder you are with the command pwd. Entering a subfolder with name NAME in the current directory is done with the command cd NAME. Entering the parent folder to the folder you are in is done with the command cd ..  .

3 Importing ROOT from Python:

In order to import the ROOT library in a python environment:
>> export PATH="/usr/local/root/bin:$PATH"
>> export PYTHONPATH="/usr/local/root/lib:$PYTHONPATH"

To test if the ROOT library is successfully imported into Python, try to open Python and import the ROOT library:
>> python
>> import ROOT
If no error appears, all is correct.
However, if this does not work (especially in El Capitain on Mac), then try from your shell the following command:
"for foo in $ROOTSYS/lib/*.so; do echo $foo && install_name_tool -add_rpath $ROOTSYS/lib $foo; done"
Nevermind what it does... just fold your hands and pray :-)

Executing a test script

Now that you have a working Python/ROOT setup, you should be able to download and execute the following Python script CalcPrimeNumbers.py, which uses ROOT (if you have trouble downloading the file, try clicking the link with the right mouse button and select "Save As"). Download the script, open a terminal and navigate to the folder where you saved the script. Execute the script with this command:
>> python CalcPrimeNumbers.py
A version of the script with more detailed documentation in the code is available here.

If you don't like to lift your fingers from the keyboard, the following two commands gets you the script and runs it:
>> wget http://www.nbi.dk/~petersen/Teaching/Stat2016/PythonRootIntro/CalcPrimeNumbers.py
>> python CalcPrimeNumbers.py

Writing your own script

To write your own scripts, or edit the downloaded ones you can simply open them in a text editor. New scripts can be written in a new document with the file extention .py at the end of their name.
Most default editors (emacs, kwrite, gedit) include syntax highlighting and many other features and any of them is a good choice. If you are looking for an advanced and easy to use editor, try kate.