PyRoot on mac osx 10.6

Hello,

I am using root on a Snow Leopard machine.

I can compile and use root without any problems, including
linking into C++ programs, in a number of ways:

Either using macports, that installs 5.24.00, or using the
source distribution and installing via ./configure --prefix=/opt/local .

It all works fine.
The problem starts when using root with python.
When I try to import root from python, I get the following:

Python 2.6.4 (r264:75706, Nov  2 2009, 13:30:40) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Fatal Python error: Interpreter not initialized (version mismatch?)
Abort trap

The python I am using here is python2.6 installed via macports.

Note that htis doesn’t happen if I use the Mac Python installation located in
/System/Library/Frameworks/Python.framework/Versions/Current/bin/python

However, I did install quite a few packages for my macports python version,
for any real work I have to use the macports version.

I suppose somewhere in the root building process there is some linking going on that relies on the builtin python version. Is there a way how to tell root (either using the ports file or using some configure flags) to use the python version I am actually using?

I manage my python versions via

python_select python26

such that

which python

yields
/opt/local/bin/python
,
which points to
/opt/local/bin/python2.6

I am using now gcc44 from the macports project.
The above-mentioned python package was compiled using apples gcc 4.2.

Thanks, Bjoern

Bjoern,

do you still have the result of the $ROOTSYS/configure run? It looks like the normal system python was selected. It probably did if the only option you gave it was --prefix. What happens in the error is that two python shared libraries are loaded, of different versions. One is loaded by the python binary, the other by libPyROOT and is the one it was linked against.

Cheers,
Wim

I do have these results.
I agree that the problem seems to be that the normal system python distribution has been chosen. I just don’t know why, and how to
tell the root install procedure to take my macports /opt/local
python installation.

If you want any information from the logfiles of the configure run,
just tell me what you need.

Bjoern

Bjoern,

in principle, setting up the other python first, before running configure, should do the trick: internally the configure script will query the currently available python for information by running it. Otherwise, the explicit CLI flags are --with-python-incdir=… and --with-python-libdir=… .

Cheers,
Wim

I definitely did have gcc44 and python26 from macports set up and selected
before starting the configure script.

I will try again using the two flags you mentioned.
Is this to be considered a bug then? Because root should have
used the active python during configure and it didn’t…

I will try that and report later.

Bjoern

This configure line did the trick:
./configure --prefix=/opt/local --with-python-incdir=/opt/local/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 --with-python-libdir=/opt/local/lib

Note the funny location of the incdir. I do not know the mac internals, but for versions of python prior to 2.6, the Python.h was found in /opt/local/include/pythonversion; for example, for python2.5, it is found in /opt/local/include/python2.5

i don’t know whether this is the thing that upsets the root configuration script.

Anyways, it works now, but it would nice if the macports version would be adapted accordingly such that one can install root via macports without running into these problems.

Thanks, Bjoern

Bjoern,

the configure script uses sys.prefix as obtained from the current python for both the lib- and inc-dirs. As such, it can’t deal with a split location as it expects both the library and Python.h under that same sys.prefix.

Are you sure the installation is proper? The python configure script has a ‘framework-install’ option so that on Mac, one has a choice to have either “Mac-style” or “unix-style.” I’m surprised to find both in a single install, though.

Cheers,
Wim

Well,
I did everything as proper as I could.
The python26 install was used via standard macports installation:
port install python26

So I think that this is a rather proper installation of python2.6 on Snow Leopard.
All the rest of the package I use are being installed this same framework.

sys.exit in python yields
’/opt/local/Library/Frameworks/Python.framework/Versions/2.6’

Python.h under /opt/local is found in
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h
/opt/local/var/macports/software/python26/2.6.4_0+darwin/opt/loca/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h

and libpython* is found in
/opt/local/lib/libpython2.6.dylib
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config/libpython2.6.a
/opt/local/var/macports/software/python26/2.6.4_0+darwin/opt/local/lib/libpython2.6.dylib
/opt/local/var/macports/software/python26/2.6.4_0+darwin/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config/libpython2.6.a

Does this correspond to a standard install? Or are the paths not as the root configure script would expect them if it only knows sys.exit?

Bjoern,

well, not sure why there appear to be two installations? In any case, the one that will be picked up with the sys.prefix that you quoted, is:

/opt/local/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config/libpython2.6.a

Meaning that the python interpreter will be linked in, which will be a problem if the interpreter that is run actually uses the .dylib (it, too, should have consistently used the .a for its build for everything to work against the .a).

What I don’t understand is that if the python binary that is available during configure, why then the sys.prefix is not:

/opt/local/var/macports/software/python26/2.6.4_0+darwin/opt/loca/Library/Frameworks/Python.framework/Versions/2.6

I.e., why doesn’t the macports binary point to the macports libraries with its sys.prefix? Are both PATH and (DY)LD_LIBRARY_PATH treated consistently when python_select python26 is done? I.e. does after that command /opt/local/bin/python pick up the shared library from /opt/local/lib, and is that library (pointing to) the macports one?

Cheers,
Wim

I run into a similar problem on snowleopard with pyroot being linked against the system python instead of the newer python setup via macports. The configure line posted above helped to make things work, but in my case (I’ve build root from the source rather than using the macport version) I had to drop the prefix argument. Now pyroot, matplotlib and cx_Oracle all live happily in the same 64bit root & python.

Hi,

I have the same problem. As I understand it for you both the following configuration worked:
./configure --prefix=/opt/local --with-python-incdir=/opt/local/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 --with-python-libdir=/opt/local/lib

At what point of the installation process and in which directory to I have to enter it if I want to use the macports root version? Do I have to remove the currently installed root version first?
Would it be possible to add that line to the default macports build process so that others don’t run into the same problem?

Thanks, --Christoph

Hi,

I have the same problem, with ROOT 5.26, Snow Leopard and the Python 2.6.4 installed from python.org (not from macports).

My python installation (2.6.4) is in

/Library/Frameworks/Python.framework/Versions/2.6

While the system python (2.6.1) is in

/System/Library/Frameworks/Python.framework/Versions/Current/bin/python

from the default python (my 2.6.4, not the system one) the sys.prefix gives:

sh-3.2# python
Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.prefix
'/Library/Frameworks/Python.framework/Versions/2.6'
>>> 

I tried to follow your suggestions and I configured ROOT with this command:

./configure macosx --with-python-incdir=/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/ --with-python-libdir=/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config/

and then compiled, but still I get the same error when I try to import ROOT from “my” python:

sh-3.2# python
Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Fatal Python error: Interpreter not initialized (version mismatch?)
Abort trap
sh-3.2#

So apparently, even if I specified the path of “my” python installation at configure time, something is still linked to another library.

Do you have any other suggestion?

Thanks a lot for your help! :slight_smile:

Ric.

Ric,

perhaps asking the obvious, but was the python installation from python.org installed with configure --enable-framework; make frameworkinstall? (I.e. does Library/2.6 point to the new python or still to the old one?)

Cheers,
Wim

Hi Wim, and thanks for your answer.

I used the standard .dmg file from python.org, I did not compile the Python source by myself.

But apparently the /Library/2.6 points to the new one:

pb-d-128-141-226-66:~ rmbianchi$ ll /Library/Frameworks/Python.framework/Versions/
total 8
drwxrwxr-x  10 root  admin  340 Oct 27 19:50 2.6
lrwxr-xr-x   1 root  admin    3 Jan 31 16:45 Current -> 2.6

and the libpython file seems to point to a new file inside the Library/2.6/ itself:

pb-d-128-141-226-66:~ rmbianchi$ ll /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config/
total 224
-rw-rw-r--  1 root  admin  43482 Oct 27 19:51 Makefile
-rw-rw-r--  1 root  admin  18265 Oct 27 19:50 Setup
-rw-rw-r--  1 root  admin    368 Oct 27 19:50 Setup.config
-rw-rw-r--  1 root  admin     41 Oct 27 19:50 Setup.local
-rw-rw-r--  1 root  admin   2128 Oct 27 19:50 config.c
-rw-rw-r--  1 root  admin   1457 Oct 27 19:50 config.c.in
-rwxrwxr-x  1 root  admin   7122 Oct 27 19:50 install-sh
lrwxr-xr-x  1 root  admin     15 Jan 31 16:45 libpython2.6.a -> ../../../Python
-rwxrwxr-x  1 root  admin   7431 Oct 27 19:50 makesetup
-rw-rw-r--  1 root  admin  11380 Oct 27 19:50 python.o
pb-d-128-141-226-66:~ rmbianchi$

where Python is this one:

pb-d-128-141-226-66:~ rmbianchi$ ll /Library/Frameworks/Python.framework/Versions/2.6/
total 7768
lrwxr-xr-x   1 root  admin       17 Jan 31 16:45 Headers -> include/python2.6
drwxrwxr-x   3 root  admin      102 Oct 27 19:50 Mac
-r-xrwxr-x   1 root  admin  3970996 Oct 27 19:50 Python
drwxrwxr-x   5 root  admin      170 Jan 31 16:46 Resources
drwxrwxr-x  15 root  admin      510 Oct 27 19:51 bin
drwxrwxr-x   3 root  admin      102 Oct 27 19:50 include
drwxrwxr-x  19 root  admin      646 Oct 27 19:51 lib
drwxrwxr-x   3 root  admin      102 Oct 27 19:50 share
pb-d-128-141-226-66:~ rmbianchi$

So apparently there is no link to the old python version from the new one.

Is there something else which I could check?

BTW the current “which python” points to the new python, not to the System one.

Do you think that compiling Python from source with --enable-frameworks could change the things?

Or maybe I could try to install Python via macports, I don’t know…

Thanks again,

Ric.

Mmm…I tried to install the newest Python, 2.6.5, via the .dmg package from python.org.

Then I compiled root_v5.26.00b with the same configure command as above.

Now when I do import ROOT, it works…but then I get errors every time I try to use a ROOT class:

pb-d-128-141-226-66:~ rmbianchi$ python
Python 2.6.5 (r265:79359, Mar 24 2010, 01:32:55) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>> c1 = ROOT.TCanvas()
Error: cannot open file "iostream"  (tmpfile):2:
*** Interpreter error recovered ***
Error: cannot open file "_string"  (tmpfile):2:
*** Interpreter error recovered ***
Error: cannot open file "vector"  (tmpfile):2:
*** Interpreter error recovered ***
Error: cannot open file "pair"  (tmpfile):2:
*** Interpreter error recovered ***
Error: cannot open file "RtypesCint.h"  (tmpfile):2:
*** Interpreter error recovered ***
TCanvas::ResizePad:0: RuntimeWarning: c1 width changed from 0 to 10

TCanvas::ResizePad:0: RuntimeWarning: c1 height changed from 0 to 10

>>> v1 = ROOT.std.vector(int)()
Error in <TPluginManager::FindHandler>: Cannot find plugin handler for TVirtualStreamerInfo! Does $ROOTSYS/etc/plugins/TVirtualStreamerInfo exist?

 *** Break *** bus error
sh: /etc/root/gdb-backtrace.sh: No such file or directory
Python(79827,0xa00d1500) malloc: *** error for object 0x29d7e0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
pb-d-128-141-226-66:~ rmbianchi$ 

Actually I checked, the file $ROOTSYS/etc/plugins/TVirtualStreamerInfo.C exists.

Mmm…I’m wondering if I should try to install Python through macports…

Just for test, I tried to install python via macports, then I configured with the command suggested above:

./configure macosx --with-python-incdir=/opt/local/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 --with-python-libdir=/opt/local/lib

But now, when I do import ROOT, I get this error:

RM-Bianchis-MacBook:~ rmbianchi$ python
Python 2.6.1 (r261:67515, Jul  9 2009, 17:39:10) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named ROOT
>>> ^D
RM-Bianchis-MacBook:~ rmbianchi$ setupROOTlocale 
RM-Bianchis-MacBook:~ rmbianchi$ python
Python 2.6.1 (r261:67515, Jul  9 2009, 17:39:10) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "lib/ROOT.py", line 86, in <module>
    import libPyROOT as _root
ImportError: dlopen(/opt/root/root_5.26.00b/lib/libPyROOT.so, 2): no suitable image found.  Did find:
	/opt/root/root_5.26.00b/lib/libPyROOT.so: mach-o, but wrong architecture
	/opt/root/root_5.26.00b/lib/libPyROOT.so: mach-o, but wrong architecture
	/opt/root/root_5.26.00b/lib/libPyROOT.so: mach-o, but wrong architecture
>>>

Sorry, I’m new to OS X, but apparently I compiled for the wrong architecture. Isn’t it “macosx” the right flag for Snow Leopard?

Thanks, and have a nice day,

Ric.

p.s. BTW, the python version for macports is the 2.6.1 …exactly the same of the Apple System python shipped with Snow Leopard!! :stuck_out_tongue: So I will try to succeed to have pyROOT running with the python .dmg from python.org, which is always the most updated one.

Hi,

[quote]>>> import ROOT

c1 = ROOT.TCanvas()
Error: cannot open file “iostream” (tmpfile):2:
*** Interpreter error recovered *** [/quote]With the same build, is root.exe working properly? (That error usually happens due to a miconfiguration/misbuild/mis-install of root)

Philippe.

Hi Philippe,

sorry, but I removed that build, because I tried many other combinations of setup.
So you can be right, that particular combination could be mis-configured.

But now looking on old posts I found that one: root.cern.ch/phpBB2/viewtopic.ph … c&start=15

So apparently there is a mismatch between the architectures.

Actually I tried now to run the ./configure without any options, and then compiled. The libpyroot is thus built for

RM-Bianchis-MacBook:~ rmbianchi$ file /opt/root/root_python265/lib/libPyROOT.so /opt/root/root_python265/lib/libPyROOT.so: Mach-O 64-bit dynamically linked shared library x86_64
RM-Bianchis-MacBook:~

In this case the ARCH macosx64 is automatically selected (why? is the Apple default?) and then I’m not able to import ROOT from the new python installation (2.6.5) because of a “wrong architecture version”, but I’m able to import it from the built-in system python (2.6.1):

custom python installation from python.org (not working):

RM-Bianchis-MacBook:~ rmbianchi$ python
Python 2.6.5 (r265:79359, Mar 24 2010, 01:32:55) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/root/root_python265/lib/ROOT.py", line 86, in <module>
    import libPyROOT as _root
ImportError: dlopen(/opt/root/root_python265/lib/libPyROOT.so, 2): no suitable image found.  Did find:
	/opt/root/root_python265/lib/libPyROOT.so: mach-o, but wrong architecture
	/opt/root/root_python265/lib/libPyROOT.so: mach-o, but wrong architecture
	/opt/root/root_python265/lib/libPyROOT.so: mach-o, but wrong architecture
>>> 

system python installation shipped with Snow Leopard (working):

RM-Bianchis-MacBook:~ rmbianchi$ file /opt/root/root_python265/lib/libPyROOT.so
/opt/root/root_python265/lib/libPyROOT.so: Mach-O 64-bit dynamically linked shared library x86_64
RM-Bianchis-MacBook:~ rmbianchi$ /usr/bin/python
Python 2.6.1 (r261:67515, Jul  9 2009, 17:39:10) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>> h1 = ROOT.TH1F()
>>>

So apparently the ./configure command picks the system python, even if “which python” points to the custom python installation.

So I do not understand how could I make it work for a standard .dmg installation from python.org.

Should I compile python from source for 32 bit instead of 64??

Thanks again for your help,

Ric.

[quote]In this case the ARCH macosx64 is automatically selected (why? is the Apple default?) [/quote]Yes this is the default because your processor is 64 bits…

[quote]custom python installation from python.org (not working):
[/quote]I am guessing it is build in 32 bits mode …

[quote]So apparently the ./configure command picks the system python, even if “which python” points to the custom python installation.[/quote]Indeed the PATH has no direct influence on configure, you would need to use the --python… option to indicate the one you want.

[quote]So I do not understand how could I make it work for a standard .dmg installation from python.org. [/quote]It sounds like you just need to compiler ROOT in 32 bits (i.e ./configure macosx …)

Cheers,
Philippe.

Yes, you are right Philippe, the standard Python installation from Python.org is compiled for i386 and PPC:

sh-3.2# file /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config/libpython2.6.a 
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config/libpython2.6.a: Mach-O universal binary with 2 architectures
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config/libpython2.6.a (for architecture ppc):	Mach-O dynamically linked shared library ppc
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config/libpython2.6.a (for architecture i386):	Mach-O dynamically linked shared library i386
sh-3.2#

So now I tried again to compile ROOT with “macosx”, from a clean ROOT source.tar, after having uninstalled the macports python, and after having reinstalled Python 2.6.5 from Python.org with the .dmg file, and providing to configure the path to the custom python framework installation:

./configure macosx --with-python-incdir=/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/ --with-python-libdir=/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config/

And now evertything seems to work!! :slight_smile:

So apparently after the first trial with the wrong architecture (default 64 bit instead of “macosx”) something got mis-configured and the system python was always linked instead of the custom one…

So thanks a lot for your help, Wim and Philippe!

And have a nice weekend!

Ric.