ImportError: No module named ROOT

Hi,

I am new to pyroot, in fact I just installed it and I am trying to run an extremely simple script to check if the things I need for my other program are successfully imported. Seems like no. Here is the simple code:

#!/usr/bin/python
import math
import sys
import numpy as np
from scipy import linspace, polyval, polyfit, sqrt, stats, randn
from ROOT import gROOT, TCanvas,TH1D,TH2D,TFile,TStyle,TLegend,TPave,TPaveStats,TPad,TPaveLabel,gStyle,gPad,TPaletteAxis,TLine
print "Yes!"

and when I try to run this file with the command: python test.py
And I get this:

Traceback (most recent call last): File “test.py”, line 6, in from ROOT import gROOT, TCanvas,TH1D,TH2D,TFile,TStyle,TLegend,TPave,TPaveStats,TPad,TPaveLabel,gStyle,gPad,TPaletteAxis,TLine ImportError: No module named ROOT_

I checked some related topics on the forum but there are many recommendations and I don’t know where to start from. Any advice is more than welcome! Btw I am using Mac OS X 10.7.5, ROOT 5.34/34 and Python 2.7.1. Merci!

Did you set the environment to run ROOT, which also sets the proper PYTHONPATH variable?

source <installation-of-root>/bin/thisroot.sh
1 Like

Hmm, no, in which folder am I supposed to do this? Pardon my ignorance!
(Btw, I have used ROOT before I installed python…)

Make sure that you get “yes” when you run:
root-config --has-python

It is definitely a yes

So, open a new terminal window and execute (“thisroot.sh” for bash and similar, “thisroot.csh” for [t]csh):
source /full/path/to/your/ROOT/bin/thisroot.sh
then (in the same terminal window) cd to your working subdirectory and try to run your python script.

Works! Thanks a lot! :sunglasses:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.