Has anybody any experience in incorporating ROOT into


no experiences, but a quick look at the source shows that python bindings in Sage are programmed directly on the CPython API and through cython. I’d expect that passing any C++ object from ROOT to Sage should then work using the CObject opaque pointer objects. From PyROOT, you can turn any bound object to a CObject using ROOT.AsCObject(), and back (with specification of the class) using ROOT.BindObject().

Of course, anything Python, I expect to be fine “as-is.”


I use ROOT Classes within Sage (especially TF1 and its numerical integration) and up to now it works very fine.

In order to I did the following:

Build PyROOT from source and pay attention that python inc-dir and python lib-dir point to the python directories coming with sage (see There might be problems if the standard python version on your PC is different from the version of python coming with sage.

In order to import ROOT classes in Sage I did the following:

Write a wrapper script “sroot”, make it executable put it in $HOME/bin:

export LD_LIBRARY_PATH=/usr/local/root/lib

create a text file init.sage in $HOME/.sage with the following content:

import sys sys.path.append('/usr/local/root/lib')

If I want to use sage with ROOT I just call “sroot” from my terminal and I can immediately import ROOT classes


Please find attached two files:

[li][color=#FF0000]cern_root-0.0.spkg[/color] - a “Sage package” (note: this is actually a simple “.tar.bz2” file so, in order to see its contents, you can easily “unpack” it using “tar -jxf cern_root-0.0.spkg”) which builds ROOT; you can have several ROOT versions installed simultaneously; if you execute “sage -i cern_root-0.0.spkg”, you will add ROOT “v5-34-00-patches” to your Sage
Last Modification Time: 2013-02-28 10:55 UTC
Known Problems: None

[code]Before calling “sage”, you can “select” the preferred ROOT
version (for the current “sage” session) using:

[bash] export SAGE_CERN_ROOT_VERSION="your_preferred_version" [csh] setenv SAGE_CERN_ROOT_VERSION “your_preferred_version”

where “your_preferred_version” is something like “trunk”,
“v5-34-00-patches”, “v5-34-05”, …

If you do not set the “SAGE_CERN_ROOT_VERSION” environment
variable, the ROOT “v5-34-00-patches” will be “selected” (see
the “SAGE_CERN_ROOT_VERSION_DEFAULT” variable in “spkg-install”).

All SAGE ROOT versions reside in the “{SAGE_CERN_ROOT_DIR}" subdirectory. The default location is "{SAGE_LOCAL}/extras/root”.

The ROOT source code will be downloaded using “svn” into the
You can also “manually” unpack any “root_*.source.tar.gz” file
in the “${SAGE_CERN_ROOT_DIR}” subdirectory in advance and set
the “SAGE_CERN_ROOT_VERSION” environment variable accordingly.

ROOT will be built using the classic “./configure; make” method.
It will use the so called “location independent installation”, in
The “configure” step uses the “SAGE_CERN_ROOT_CONFIG” environment
variable, which is expected to provide all desired “./configure”
flags. Before executing “sage -{i|f} cern_root-0.0.spkg”, you can
set it using:
[bash] export SAGE_CERN_ROOT_CONFIG="any flags you like" [csh] setenv SAGE_CERN_ROOT_CONFIG “any flags you like”
If you do not set the “SAGE_CERN_ROOT_CONFIG” environment variable,
the “–all --enable-explicitlink --enable-soversion --disable-qt
–disable-qtgsi” flags will be used (see “spkg-install”).



  1. You can “update” the source code from the “svn” repository
    (e.g. when using a ROOT “patches” branch) and “rebuild” the
    updated version by executing “sage -f cern_root-0.0.spkg”.
  2. You can also “rebuild” a particular ROOT version from scratch:
    subdirectory and then execute “sage -f cern_root-0.0.spkg”.
  3. The “spkg-install” script assumes that on a 64-bit machine the
    “sage” has been built as a 64-bit application, too. If you are
    using a 32-bit version of “sage” on a 64-bit machine, you will
    need to “manually enforce” the architecture used by the ROOT
    “configure” script (i.e. the architecture to build for must not
    be “guessed automatically”). In this case you MUST define the
    “SAGE_CERN_ROOT_CONFIG” environment variable (see above) and
    the very first flag in it must be “your_32bit_architecture”,
    that is something like “linux” or “macosx”, for example.
    In any case, if you do not set the “SAGE_CERN_ROOT_CONFIG”
    variable, the ROOT architecture will be “guessed automatically”.[/code]
    [li][color=#FF0000][/color] - a “bash” shell script which fixes “hardcoded” paths in some Sage scripts in its “{SAGE_LOCAL}/bin" subdirectory (i.e. in "{SAGE_ROOT}/local/bin”)
    Last Modification Time: 2014-12-04 12:07 UTC
    Known Problems: None

[code]The “” replaces “hardcoded” paths in some relevant
“scripts” in the “${SAGE_LOCAL}/bin” subdirectory with SAGE_* “relative”
paths (git-cvsserver *-config *-makefile gap gphelp maxima [rx]maxima R).

Before executing “” … cd “${SAGE_LOCAL}/bin”

I general, it is a good idea to build Sage in its “final” location.
If you build Sage somewhere and then copy or move the entire build
tree to another location, then you must run “./sage” once so that
various “hardcoded” locations get updated (you will see a message
saying “Changing/Updating various hardcoded paths…”).
However, at least up to “sage-6.4.1”, this will NOT “fix” paths in
“scripts” which reside in the “${SAGE_LOCAL}/bin” subdirectory.
That is why you need to execute “”, too.

Note: the same problem appears if you install Sage from a pre-built
binary tarball in a location (i.e. a subdirectory) which does not
exactly follow the one which was used to build this binary distribution.[/code][/li][/ul]

I am stupid. No?
Pepe Le Pew.
cern_root-0.0.spkg (3.79 KB) (2.36 KB)