Windows 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:

If you don't have python already in your Windows installation (check!), download the installation file for your version of windows from this page and install the contents. However, note that it should be the 32 bit version for it to be compatible with ROOT.
After installing Python you need add a few things to your enviromental variables, in order make your computer recognize the python extentions (.py). To do this on Windows 7 and 10 press start->computer->system properties->Advanced System settings->Enviromental Variables. In the bottom list, under "System variables" find the variable called "Path". Press edit, and add ";C:\Python27" (If have installed Python at another location, enter that instead). Press ok. Next, find the variable called PATHEXT. Here add ";.PY". Now your computer should recognize Python.

1.1 Testing your python installation

In windows the terminal is opened by clicking on the Start button and opening the "Command prompt", which can be found under "All Programs > Accessories" or by searching for "Powershell" in the start menu. Open a terminal and type:
>> python --version
Python is installed if the output is similar to:
Python 2.7.12

If you are unsure whether you installed the 64 or 32 bit version of python, you can open yours "Command prompt" or "Powershell" and type python. This gives you a python shell. Now type (or copy in) import struct;print( 8 * struct.calcsize("P")). If the answer is 32, then your installation is the 32 bit kind.

2 Installing ROOT:

First, download the installation file for windows from this page. Click on the link to the page for the 5.34 version. Then scroll down to the Windows section in the Binaries section, and choose the "Windows Visual Studio 12" executable, which you should install. When installing, choose the option "Add ROOT to the system PATH for current user", and the ROOT installer should automatically add the relevant paths and extentions to the environmental variables.

At this point ROOT is installed. In order to test if ROOT can run, type the following in the "Command prompt" or "Powershell":
>> root (this command opens root now)
To exit ROOT, type ".q" or "exit()".

3 Importing ROOT from Python:

In order to import the ROOT library in a python environment, python needs to know where ROOT is installed, this is again done by editing the system Enviromental Variables:

This part should be done automatically by the installer... but here is how you do it manually: press start->computer->system properties->Advanced System settings->Enviromental Variables. In the bottom list, under "System variables" find the variable called "Path". Press edit, and add new ";C:\root_v5.34.36\bin;C:\root_v5.34.36\lib". (If have installed ROOT at another location, enter that instead).

However, you also need to add "PYTHONPATH" to your environmental variables, and it should have the same value as the ROOT part of your "PATH", in this example "C:\root_v5.34.36\bin". This might have to be done for both user and system variables.
If this doesn't work, try restarting your machine.

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. If this however does not work, you can test if the python path is correctly set by opening a python terminal and entering: "import sys; print sys.path" There should then be an entry containing the ROOT directory you set earlier.


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.

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.
More advanced editors for Windows (and OS X) are available at notepad++(Windows only) and sublime text. They include syntax highlighting and many other features.