PyRoot (Root 5.14/00) & Python2.5 on WinXp

Hi all,

hsimple.py doesn’t run on my WinXp notebook:

[quote] C:\root\tutorials\pyroot>python hsimple.py
Traceback (most recent call last):
File “hsimple.py”, line 13, in
from ROOT import TCanvas, TFile, TProfile, TNtuple, TH1F, TH2F
File “C:\root\bin\ROOT.py”, line 83, in
import libPyROOT as _root
ImportError: No module named libPyROOT[/quote]

So I modified ROOT.py:

[code]— ROOT.py.orig 2006-12-08 08:45:58.000000000 +0900
+++ ROOT.py 2006-12-27 23:35:02.940800000 +0900
@@ -21,6 +21,7 @@

system and interpreter setup ------------------------------------------------

import os, sys, time
import string as pystring
+import imp

there’s no version_info in 1.5.2

if sys.version[0:3] < ‘2.2’:
@@ -80,6 +81,9 @@
dlflags = sys.getdlopenflags()
sys.setdlopenflags( 0x100 | 0x2 ) # RTLD_GLOBAL | RTLD_NOW

+if pystring.find( sys.platform, ‘win32’) == 0:

  • dllpath = os.path.join( os.getenv(‘ROOTSYS’), ‘bin’, ‘libPyROOT.dll’)
  • imp.load_dynamic(‘libPyROOT’, dllpath)
    import libPyROOT as _root

reset dl flags if needed

[/code]

and then python.exe complained that it couldn’t find python24.dll.

After installing python-2.4.4.msi, it runs ok with the above modification.

What’s wrong with my windoze root/python installation?
Are there any better ways to workaround?

Yours,

Kazuyoshi

p.s. the followings are my personal env.vars setting relevant to root/python:

INCLUDE: %ROOTSYS%\include;%MSVCDIR%\include
LIB: %ROOTSYS%\lib;%MSVCDIR%\lib
MSVCDIR: C:\msvc
PATH: %ROOTSYS%\bin;%PYTHONDIR%;%MSVCDIR%\bin;%MSVCDIR%\dll;C:\Program Files\gawk-mbcs-win32-20051223;C:\gs\gs8.54\bin;C:\gs\gs8.54\lib

PYTHONDIR: C:\Python25
PYTHONHOME: C:\Python25
PYTHONPATH: %ROOTSYS%\bin;%ROOTSYS%\lib
ROOTSYS: C:\root

I played around the PyROOT examples (which have been reorganized into the `pyroot’ subdirectory).

`os.linesep’ is ‘\r\n’ on Windoze and the following change should be made:

[code]— demoshelp.py.orig 2006-12-12 06:56:35.000000000 +0900
+++ demoshelp.py 2006-12-28 12:32:08.000000000 +0900
@@ -1,4 +1,3 @@
-import os
from ROOT import TCanvas, TPaveText
from ROOT import gROOT

@@ -29,7 +28,7 @@
… Use middle button to pop overlapping objects
… Use right button to get an object sensitive pop-up
"""
-for line in text.split( os.linesep ):
+for line in text.split( ‘\n’ ):
hdemo.AddText( line )

hdemo.SetAllWith( ‘…’, ‘color’, 2 )
[/code]

Because of the reorganization, modification like the following seems to be needed:

[code]— fit1.py.orig 2006-12-12 06:56:35.000000000 +0900
+++ fit1.py 2006-12-28 13:02:10.000000000 +0900
@@ -4,6 +4,7 @@

from ROOT import TCanvas, TFile, TPaveText
from ROOT import gROOT, gBenchmark
+import os

gROOT.Reset()
c1 = TCanvas( ‘c1’, ‘The Fit Canvas’, 200, 10, 700, 500 )
@@ -45,7 +46,7 @@
fitlabel = TPaveText( 0.6, 0.3, 0.9, 0.80, ‘NDC’ )
fitlabel.SetTextAlign( 12 )
fitlabel.SetFillColor( 42 )
-fitlabel.ReadFile( ‘fit1_C.C’ )
+fitlabel.ReadFile( os.path.join(’…’, ‘fit’, ‘fit1_C.C’) )
fitlabel.Draw()
c1.Update()
gBenchmark.Show( ‘fit1’ )
[/code]

--- geometry.py.orig	2006-12-12 06:56:35.000000000 +0900
+++ geometry.py	2006-12-28 13:10:00.000000000 +0900
@@ -1,9 +1,10 @@
 import ROOT
+import os
 
 
 ROOT.gROOT.Reset()
 
 # the na49.C file was generated, so no python conversion is provided
-ROOT.gROOT.Macro( 'na49.C' )
+ROOT.gROOT.Macro( os.path.join('..','geom','na49.C') )
 execfile( 'na49visible.py' )
 execfile( 'na49geomfile.py' )

[code]— rootmarks.py.orig 2006-12-12 06:56:35.000000000 +0900
+++ rootmarks.py 2006-12-28 13:18:20.000000000 +0900
@@ -6,6 +6,7 @@

import ROOT
+import os

use ROOT macro to make sure that bench numbers get updated in one place

-ROOT.gROOT.Macro( ‘rootmarks.C’ )
+ROOT.gROOT.Macro( os.path.join(’…’,‘rootmarks.C’) )
[/code]

By the way, where can we find the aptuple.txt' which is used inmrt.py’?
Is it the same as the one at http://service-spi.web.cern.ch/service-spi/app/releases/SEAL/snapshot-old/src/Scripting/PyROOT/examples/aptuple.txt?

Yours,
Kazuyoshi

Dear all,

I’m sorry, I found that I don’t need to make the following modification if I use Python-2.4.x.

Yours,
Kazuyoshi

Kazuyoshi,

yes, that’s an oldie from SEAL, as you’ve found. As for p2.5, it is supported (there are quite a few changes b/c of 64bits support), but you’ll have to build against it from source: ATLAS/LHCb at CERN still use p2.4, which is why that version is chosen for the standard installation.

Cheers,
Wim

Kazuyoshi - thanks for the hint on the import of the dll. I’m using python 2.5 and that saved me a bunch of time.