Home | News | Documentation | Download

Python ROOT import issue

Hey folks!

There’s a problem I really am getting insane about. Being a complete sourcecode newbie, I got managed to install ROOT on OS X 10.6. It works (at least it seems to). But there’s one issue that remains, which is that python simply won’t load the ROOT module.

The problem itself is that I just don’t know where Python.h and PyROOTLib.so are.
In another thread in this forum I found ./configure macosx64 --enable-python --with-python-incdir=/Library/Frameworks/Python.framework/Versions/Current/include/python2.7/ --with-python-libdir=/Library/Frameworks/Python.framework/Versions/Current/lib/ --enable-builtin-pcre
This seemed quite reasonable to me and I jogged it down in my Terminal, still it didn’t change a thing. After starting python, if I type in >>> import ROOT it responds with Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named root
As said, I am a complete newbie on this kind of stuff, and I don’t want to wreck my Mac so that in the end it’s as slow as a PC… so can anyone please tell me what to do? :frowning:

Thanks!

Hi,

I’m not a mac expert, but one thing caught my eye:

[quote=“BakersCookies”]>>> import ROOT it responds with Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named root
[/quote]

Did you cut and paste the command and error messages? Are you sure that you typed import ROOT and not import root? The error message suggests the latter. If you really did type what you said, then some funky case stuff is going on…

Good luck,
Charles

Hey there and thanks for the fast answer.
That was my bad. I did type in “root”, not “ROOT”.

In the installation instructions for PyROOT it says:

Does anyone know where those two files are on mac os x? Maybe that would help me already.

Hi,

but did you afterwards try “import ROOT” as well?

As for the location of the include and lib dirs, they’ll be located automatically by the configure script if you have the python version that you’re interested in upfront in your PATH.

Cheers,
Wim

Yup, I did.
So installing PyROOT is basically simply

cd root (my directory for root)
./configure
make
make install
export LD_LIBRARY_PATH=$ROOTSYS/lib:$PYTHONDIR/lib:$LD_LIBRARY_PATH
export PYTHONPATH=$ROOTSYS/lib:$PYTHONPATH

That should basically be it, right? Did I miss something?

That’s pretty much it, except that I don’t add $PYTHONDIR/lib on my Mac (but I don’t have a local install under /Library either; I do have additional fink pythons under /opt).

Cheers,
Wim

Maybe I should try installing ROOT location independently.

How do I do the following?

Add bin/ to PATH and lib/ to LD_LIBRARY_PATH. For the sh shell family do: . bin/thisroot.sh and for the csh shell family do: source bin/thisroot.csh

As it says source the script in the ROOT installation directory.

Cheers,
Wim

everything fine, but terminal gives me following error:

source bin/thisroot.csh -bash: bin/thisroot.csh: line 15: syntax error near unexpected token `(' -bash: bin/thisroot.csh: line 15: `set ARGS=($_)'
is that a sourcecode mistake? or mine?

EDIT: A friend advised me to switch to the ROOT dir and execute python -i. gives me following error:

ImportError: dlopen(./libPyROOT.so, 2): no suitable image found. Did find: /Users/kaiporten/root/lib/libPyROOT.so: mach-o, but wrong architecture /Users/kaiporten/root/lib/libPyROOT.so: mach-o, but wrong architecture ./libPyROOT.so: mach-o, but wrong architecture

Hi,

as the instructions state, for bash one should use “bin/thisroot.sh” and not “bin/thisroot.csh” which of course will give an error, since the syntax for the csh family of shells is different.

As for the dlopen error, it looks like there’s a mix of 32-bit python with 64-bit pyroot (or vice-versa). Which version of MacOS do you have? What are the first lines when you start up python? And what does which python yield?

Cheers,
Wim

Okay sorry for that. Read the manual, I know.

First off, it’s a 64 bit Intel Core 2 Duo.

First lines in python are:

Python 2.6.6 (r266:84374, Aug 31 2010, 11:00:51) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "help", "copyright", "credits" or "license" for more information.

I found something via my system profiler. In the Frameworks tab, there’s two entries for “Python”, 2.6.1 and 2.6.6, and 2.6.6 (which is the version that I installed lately) doesn’t have 64 bit support.

Okay, so reinstall python? Mac has this concept of “fat binaries” and for python it preferred to install 32b only on 64b boxes, b/c most downloadable python extension libraries were 32b. Not sure whether this has changed, but if your local install only has 32b support, than either ROOT needs to be build for 32b, or python for 64b. For a while we also had a python64 in $ROOTSYS/bin, but I believe that is gone by 10.6 as the python shipping with that should be okay.

Did you try running the system p2.6.1 instead of the local one?

Cheers,
Wim

I tried configuring root with “macosx” architecture, because i thought that was 32bit mode. Looks like I’m wrong:

ld: warning: in cint/cint/src/dict/longif3.o, file was built for unsupported file format which is not the architecture being linked (i386) Undefined symbols: "_G__cpp_setupG__stream", referenced from: _G__pragma in pragma.o "_main", referenced from: start in crt1.10.6.o (maybe you meant: _G__main, _G__main$non_lazy_ptr ) "_G__unredirectcerr", referenced from: _G__process_cmd in pause.o _G__process_cmd in pause.o "_G__unredirectcout", referenced from: _G__process_cmd in pause.o _G__process_cmd in pause.o "_G__redirectcerr", referenced from: _G__process_cmd in pause.o _G__process_cmd in pause.o "_G__redirectcout", referenced from: _G__process_cmd in pause.o _G__process_cmd in pause.o ld: symbol(s) not found collect2: ld returned 1 exit status make: *** [cint/cint/main/cint_tmp] Error 1

Anyways, how do I uninstall python (especially: how am I sure I uninstall the right version?) and how do I open version 2.6.1?

cheers and thanks for helping me out!

[quote]ld: warning: in cint/cint/src/dict/longif3.o, file was built for unsupported file format which is not the architecture being linked (i386)[/quote]This sounds like after redoing the configure you did not issue ‘make distclean’ to make sure that all the .o files are rebuild in 32bit format.

Cheers,
Philippe.

Not sure … not a Mac expert here. I’d think that if the various pythons show up under /Applications in Finder, that you can safely trash them. Alternatively, removing the full package should do the trick as well, assuming that /usr/local/bin/python is a symlink and not a binary.

Cheers,
Wim

Hi,

The standard PYTHON installation on OSX 10.6.5 can be used in 64bit or 32bit mode. The latest version of the ROOT binaries (v5.28 for example) cannot be used because they are built against PYTHON version 2.6.2, rather than 2.6.1, which comes with OSX 10.6.5. If you rebuild ROOT in 32bit mode then you can run PYTHON in 32bit mode via

Using a 32bit build of ROOT built against OSX 10.6.5 (PYTHON 2.6.1)

all works as hoped

without

PYTHON runs in 64bit mode and therefore is unable to load the 32 bit version of ROOT

It is not necessary to reinstall PYTHON.

Regards,

Will

A post was split to a new topic: Jupyter: import ROOT