Installation of Python (through Anaconda - highly recommended)

Most modern laptops already have Python installed, so always first check, if that is the case!

If that is somehow not the case, then we recomment using Anaconda, which is a framework for Python that also includes programs such as the jupyter notebook and the editor Spyder.

It is required for Windows to easily install packages, and we recommend it for macOS and Linux users as well. Spyder is an IDE (Integrated Development Environment) which means that it is integrated editor, that lets you execute program parts and allows you to inspect the value of variables (and other things) during execution - all the good stuff you may (should?) know from MATLAB.

Since we will be using Python 2.7, you must install Anaconda2 (version 5.x) which is for Python 2.7. Python 3.6 might work for Linux/macOS, but we have not fully tested this, and it won't work in Windows.

Python is often used with packages, which enables new (and often extremely useful) features possible in your programs. We will of course make use of packages (the most common ones, and a few specific for statistics), which in this course are:

  • scipy - A collection of tools for scientific computing.
  • numpy - Numerical Python, with powerful N-dim arrays and linear algebra commands.
  • matplotlib - The Python standard for plotting graphs and histograms.
  • iminuit - The Python interface to the minimisation package Minuit.
  • probfit - Functions for constructing complex fits (used with iMinuit).

    0. A word of caution

    Anaconda will install its own Python version and a package manager. For them to work properly, Anaconda must add its path to the PATH environmental variable. However, Anaconda will PREPEND its path, meaning its Python version and its packages will supercede any Python installation and packages you already may have. This should not have any ill effects. If you experience issues elsewhere in your system or with your standard Python installation, try first to move the Anaconda path to the back of the PATH environmental variable.

    1. Download and install Anaconda

    Download and install Anaconda2 version 5.x, Python version 2.7 from here.

    Windows/macOS: You MUST select "Add Anaconda to my PATH" in the advanced options page of the installer, if it's not already checked.
    Linux: You must TYPE yes (don't just hit enter!) when asked if you want to add Anaconda to your path in your startup script.

    1b. Windows only: Download and install additional programs

    Some Python packages require compilation of FORTRAN/C/C++ code which is easy on macOS/Linux because compilers are most often included.

    Download and install the Microsoft Visual C++ Compiler for Python 2.7 from here.

    2. Update and install additional Python packages

    Anaconda comes with many common Python packages, including numpy, scipy, matplotlib, scikit-learn, etc.

    We just need to install iminuit, which is a powerful and proper fitting tool (superior to numpy's and scipy's), and a helper package, probfit.

    Windows: Open a command line (Win+R, type "cmd") and run the code below one line at a time. Press y when needed.
    Linux/macOS: Open your favourite terminal, e.g. bash, and run the code below one line at a time. Press y when needed.

    conda update conda
    conda install iminuit
    pip install -i https://pypi.anaconda.org/pypi/simple probfit
    

    3. Needed configurations for Spyder

    If you use Spyder, you will need to change one thing to run the scripts.

    REQUIRED: Go to Tools - Preferences - Python interpreter - click "Set UMR excluded (not reloaded) modules" - enter "iminuit, probfit" into the box.
    OPTIONAL: Go to Tools - Preferences - IPython console - Graphics - Graphics backend - set it to "Automatic".
    This will make figures open in new windows instead of being embedded in the ipython console.

    4. Congratulations, you have everything you need.



    Manual Installation (not recommended for Linux/macOS, won't work for Windows)

    You should not follow these steps if you have Anaconda.

    If you already have experience with Python and have packages and IDEs installed the way you prefer, these are the packages you will need immediately.
    We recommend Python 2.7, though Python 3.6 (maybe 3.5) might work.

    Packages needed

    If you will not be using Anaconda, run the following:

    # Python 2.7.x:
    pip2 install --user --upgrade numpy
    pip2 install --user --upgrade scipy
    pip2 install --user --upgrade iminuit
    pip2 install --user --upgrade probfit
    pip2 install --user --upgrade matplotlib
    
    # Python 3.6.x:
    pip3 install --user --upgrade numpy
    pip3 install --user --upgrade scipy
    pip3 install --user --upgrade iminuit
    pip3 install --user --upgrade matplotlib
    # probfit must be installed like this:
    cd $HOME &&
    git clone git://github.com/iminuit/probfit.git &&
    cd probfit &&
    pip3 install cython --user &&
    pip3 install . --user &&
    cd
    

    Verify that everything works by opening Python and importing the above packages.


    Last updated 8th of November 2017.