Problem import ROOT.py on Mac OS X

I’m trying to import ROOT.py, my $PYTHONPATH containes the $ROOTSYS/lib directory and ROOT.py can be found, however I’m getting the following

[ram@dome ram]$ python
Python 2.4.2 (#1, Mar 14 2006, 18:10:32)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.

import ROOT
Traceback (most recent call last):
File “”, line 1, in ?
File “/Users/ram/opt/root/lib/ROOT.py”, line 74, in ?
from libPyROOT import *
ImportError: Inappropriate file type for dynamic loading

where libPyROOT.dylib is the following filetype

libPyROOT.dylib: Mach-O dynamically linked shared library ppc
libPyROOT.so: symbolic link to `libPyROOT.dylib’

anybody know why I’m unable to import ROOT.py?

Hi,

how did you install ROOT, and which version are you using? As well, which version of MacOS do you have?

[quote]libPyROOT.dylib: Mach-O dynamically linked shared library ppc
libPyROOT.so: symbolic link to `libPyROOT.dylib’[/quote]
Well, on my Mac (10.3.9) these files are two different ones, no links.

Cheers,
Wim

Sorry, I should have stated that in my original post. I’m using Mac OS X 10.4.5 and ROOT 5.10/00 built from source using the following configure options

./configure --disable-globus --enable-python --prefix=$ROOTSYS --etcdir=$ROOTSYS/etc --libdir=$ROOTSYS/lib --incdir=$ROOTSYS/include

Hi,

hmm, can’t check for MacOS 10.4, as I don’t have access to such a machine, but looked into the python source to see where the error comes from: it is reported if the lib that is loaded isn’t Mach-O?!

The other thing that I can think of (but again, technically speaking that’s for 10.3), is that python may be not installed as a Framework? In that case libPyROOT wouldn’t be the problem, but the python lib being linked with it.

Can you relink libPyROOT after removing $(PYTHONLIB) from pyroot/Module.mk? You don’t need to link with libpythonx.y if you’re loading ROOT.py into python, as that will already be available and loaded by python itself (you do need it, when loading python into CINT). If the cause is a problem with the python installation, then not linking with the python shared lib used to fix it (on 10.3).

Cheers,
Wim

Getting a bit further with this, I’ve got python-2.4.2 installed from Darwin ports and it looked like ROOT was building against the system python-2.3.5 and as the system python is built with gcc-3.3 and I’m compiling ROOT with gcc-4.0.1 that explains the incompatible type.

So I’ve rebuilt ROOT with the following extra options

–with-python-incdir=/opt/local/include/python2.4 --with-python-libdir=/opt/local/lib

So that ROOT knows which python to build against

This however does not seem to work either, using python-2.4.2 I get the following error

import ROOT
Traceback (most recent call last):
File “”, line 1, in ?
File “/Users/ram/opt/root/lib/ROOT.py”, line 74, in ?
from libPyROOT import *
ImportError: Inappropriate file type for dynamic loading

and with the system python-2.3.5 I get

import ROOT
Traceback (most recent call last):
File “”, line 1, in ?
File “/Users/ram/opt/root/lib/ROOT.py”, line 74, in ?
from libPyROOT import *
TypeError: type() argument 1 must be string, not str

So it looks like its still not being built against the correct version of python. Are there any other options that specify which python to build against?

I need to use python-2.4.x as I have some scripts which I want to use with ROOT that use python-2.4.x only features.

Thanks Adam

Hi Adam,

the configure script searches in a couple of standard places; /opt/local is not one of them. So yes, without making those directories explicit, it will use the system installation. The configure script also prefers Framework installs, as I’ve not been able to get it to work otherwise (of course, that’s still talking 10.3, but I have no indication that it improved on 10.4).

If you suspect that it is still a version problem, then you can use ‘ldd’ or ‘objdump -p’ to check which version libPyROOT.so was linked against. Also, make sure that DYLD_LIBRARY_PATH points to your private install.

But could you please try a framework install first? ./configure --enable-framework make sudo make frameworkinstall

which is cleaner also for other uses.

Cheers,
Wim

But isn’t the same configuration script used on all platforms? And only OS X uses frameworks, so why does ROOT only work with Frameworks on OS X?

Unfortunately not for my case, as the python-2.4 from darwinports is not installed as a framework.

Cheers

Adam

Hi Adam,

nothing to do with ROOT, purely an issue with python on Mac, and I’m willing to bet that you would have the same problem with any C++ extension lib that links to the python lib. Not sure about the exact details in your case (you have, after all, a different error message), but what happened for me on 10.3, is that the python interpreter was created twice: once by the python executable, and once by loading the shared lib (which is why not linking libPyROOT.so with the python shared lib “fixed” this problem). In the framework install, however, everything resolved fine on loading, there was then only one interpreter in memory, and no so problems.

Weird … I’m not familiar with darwinports, but what I found by looking at their configuration file for python2.4, is that it does enable frameworks. What I don’t understand then, is how you can have an installation ending up under /opt/local/include? It’s supposed to go under ${prefix}/Library/Frameworks (as per the details on python24.darwinports.com)?

Cheers,
Wim

Wim

That makes sense.

Looking into this more closely it appears that that a Framework is installed as well, I’ll try linking against this Framework and see if that helps.

darwinports.com has nothing todo with the darwinports project, the official darwinports website is located at http://www.darwinports.org. See the following page on the darwinports.org site for more information on this

http://darwinports.org/archives.php?id=11

Cheers

Adam

configuring ROOT with

./configure --prefix=$ROOTSYS --etcdir=$ROOTSYS/etc --libdir=$ROOTSYS/lib --incdir=$ROOTSYS/include --disable-globus --disable-krb5 --disable-ldap --disable-xrootd --disable-builtin-freetype --disable-builtin-pcre --enable-python --with-python-incdir=/opt/local/Library/Frameworks/Python.framework/Headers --with-python-libdir=/opt/local/Library/Frameworks/Python.framework

which should link ROOT against the Python.framework installed from darwinports. However I’m still getting the same error

Python 2.4.2 (#1, Mar 14 2006, 18:10:32) 
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/Users/ram/opt/root/lib/ROOT.py", line 74, in ?
    from libPyROOT import *
ImportError: Inappropriate file type for dynamic loading
>>>

it looks like libPyROOT is being linked against the correct python version

[ram@zippy lib]$ otool -L libPyROOT.so            
libPyROOT.so:
        /Users/ram/opt/root/lib/libPyROOT.dylib (compatibility version 0.0.0, current version 0.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.1.5)
        /Users/ram/opt/root/lib/libCore.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/ram/opt/root/lib/libCint.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/ram/opt/root/lib/libHist.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/ram/opt/root/lib/libGraf.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/ram/opt/root/lib/libGraf3d.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/ram/opt/root/lib/libGpad.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/ram/opt/root/lib/libTree.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/ram/opt/root/lib/libMatrix.dylib (compatibility version 0.0.0, current version 0.0.0)
        /opt/local/Library/Frameworks/Python.framework/Versions/2.4/Python (compatibility version 2.4.0, current version 2.4.0)
        /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.3.0)
        /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
[ram@zippy lib]$ 

And trying to import ROOT.py in the system python fails with the following error

[ram@zippy ram]$ python2.3
Python 2.3.5 (#1, Mar 20 2005, 20:38:20) 
[GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Fatal Python error: Interpreter not initialized (version mismatch?)
Abort trap

Which looks like ROOT is being linked against the correct python version

Any ideas?

Cheers

Adam

Hi Adam,

so I installed darwinports python24 (still MacOSX 10.3), in an attempt to reproduce your problem. Search and try and puzzle as I may, and although I am capable of working myself into quite some trouble this way, I did not see your particular error appear … :frowning:

The only piece of information that I haven’t asked from you are the values of your DYLD_LIBRARY_PATH and LD_LIBRARY_PATH which seem to be the easiest roads to trouble. Did you do anything special with those?

Cheers,
Wim

I don’t think I’m doing anything special with them

[ram@ram-port ram]$ echo $LD_LIBRARY_PATH
/Users/ram/opt/pylal/lib:/Users/ram/opt/root/lib:/opt/local/lib:/Users/ram/opt/lal/lib:/Users/ram/opt/glue/lib:/Users/ram/opt/gt-4.0.1/lib
[ram@ram-port ram]$ echo $DYLD_LIBRARY_PATH 
/Users/ram/opt/pylal/lib:/Users/ram/opt/root/lib:/opt/local/lib:/Users/ram/opt/lal/lib:/Users/ram/opt/glue/lib:/Users/ram/opt/gt-4.0.1/lib

Cheers

Adam

Hi Adam,

the /opt/local/lib contains a libpython2.4.dylib from the darwinports install in my case, which did intefere in my case in some combination of pythons. Other than that, I’m out of ideas. I should kick my boss into paying up for a 10.4 upgrade. :confused:

Oh, maybe one more thing, I find this on the python.org site:

[quote]Universal Mac OSX binary for Python 2.4.3

The Universal MacPython 2.4.3 image contains an installer for python 2.4.3 that works on Mac OS X 10.3.9 and later on both PPC and Intel macs and includes both bsddb and readline.
Published: Fri, 31 Mar 2006 04:17:48 +0000[/quote]
Since darwinports is only at 2.4.2 (yesterday, anyway), would you mind trying out this new install instead? (Haven’t tried it, as I had already installed 2.4.3 from source.)

Cheers,
Wim

Not having /opt/local/lib in my $LD_LIBRARY_PATH/$DYLD_LIBRARY_PATH also results in the same error. Can you get ROOT.py imported into a python from darwinports on 10.3?

Using the installer from python.org and building ROOT against this framework results in the same error when trying to import ROOT.py

[ram@zippy ram]$ python
Python 2.4.3 (#1, Mar 30 2006, 11:02:15) 
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/Users/ram/opt/root/lib/ROOT.py", line 74, in ?
    from libPyROOT import *
ImportError: Inappropriate file type for dynamic loading

my libPyROOT.so is built against the following libraries

[ram@zippy lib]$ otool -L libPyROOT.so 
libPyROOT.so:
        /Users/ram/opt/root/lib/libPyROOT.dylib (compatibility version 0.0.0, current version 0.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.1.5)
        /Users/ram/opt/root/lib/libCore.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/ram/opt/root/lib/libCint.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/ram/opt/root/lib/libHist.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/ram/opt/root/lib/libGraf.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/ram/opt/root/lib/libGraf3d.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/ram/opt/root/lib/libGpad.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/ram/opt/root/lib/libTree.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/ram/opt/root/lib/libMatrix.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Library/Frameworks/Python.framework/Versions/2.4/Python (compatibility version 2.4.0, current version 2.4.0)
        /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 7.3.0)
        /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)

Cheers

Ada

Hi Adam,

yes, that works just fine for me.

Cheers,
Wim

What options do you pass to configure?

Cheers

Adam

Hi Adam,

No extra options for darwingports, just the defaults. When installing python from tar.bzip, I used --enable-shared --enable-framework, followed by make; make frameworkinstall. When installing ROOT, I used --enable-reflex --enable-roofit --enable-cintex (none of which have anything to do with python, really) and --with-python-incdir --with-python-libdir as appropriate in case of linking against darwinports (the installed products from the .tar.bzip are found automatically).

When I compare the final product with otool, it is linked against the same libs as you reported earlier, but not /usr/lib/libstdc++.6.dylib nor /usr/lib/libgcc_s.1.dylib.

Cheers,
Wim

As you’re building on Panther you’ll be using gcc-3.3 and these extra libraries are specific to gcc-4.x. So it looks like it could be a gcc-4.x issue.

I’ll see if building ROOT with gcc-3.3 helps matters any…

Nope, same error! This time libPyROOT.so is linked against these libraries

[ram@ram-port ram]$ otool -L ~/opt/root/lib/libPyROOT.so
/Users/ram/opt/root/lib/libPyROOT.so:
        /Users/ram/opt/root/lib/libPyROOT.dylib (compatibility version 0.0.0, current version 0.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.1.5)
        /Users/ram/opt/root/lib/libCore.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/ram/opt/root/lib/libCint.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/ram/opt/root/lib/libHist.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/ram/opt/root/lib/libGraf.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/ram/opt/root/lib/libGraf3d.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/ram/opt/root/lib/libGpad.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/ram/opt/root/lib/libTree.dylib (compatibility version 0.0.0, current version 0.0.0)
        /Users/ram/opt/root/lib/libMatrix.dylib (compatibility version 0.0.0, current version 0.0.0)
        /opt/local/Library/Frameworks/Python.framework/Versions/2.4/Python (compatibility version 2.4.0, current version 2.4.0)

Cheers

Adam

Platform: Tiger (OSX 10.4.6)
Xcode: 2.2.1
gcc: 4.0.1 (Apple, build 5250)
Python: 2.4.3, from pythonmac.org, Universal package
ROOT: cvs 0514
Error log:

[code]
Python 2.4.3 (#1, Mar 30 2006, 11:02:15)
[GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin
Type “help”, “copyright”, “credits” or “license” for more information.

import ROOT
Traceback (most recent call last):
File “”, line 1, in ?
File “ROOT.py”, line 74, in ?
from libPyROOT import *
ImportError: Inappropriate file type for dynamic loading

[/code][/code]

I do not see any problem with the CVS version with

import ROOT

It is likely that you did not install from source correctly.
In particular, my guess is that you forgot to do
make install
or
make map

Rene