Environment variables for PyRoot in OS X

Hi all,

I’ve been struggled during some time today on how to get running PyRoot in Snow Leopard. I was getting the following error:

[pb-d-128-141-141-210.cern.ch]:~% python
Python 2.5.4 (r254:67917, Dec 23 2008, 14:57:27) 
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Fatal Python error: Interpreter not initialized (version mismatch?)
zsh: abort      python

and I was setting-up my environment as follows:

export ROOTSYS=/Users/sevilla/software/root/5.26.00
export PYTHONDIR=/Library/Frameworks/Python.framework/Versions/Current 
export LD_LIBRARY_PATH=${PYTHONDIR}/lib:${LD_LIBRARY_PATH}
export DYLD_LIBRARY_PATH=${PYTHONDIR}/lib:${DYLD_LIBRARY_PATH}

What I do not understand is why setting-up as

export ROOTSYS=/Users/sevilla/software/root/5.26.00
export PYTHONDIR=/Library/Frameworks/Python.framework/Versions/Current 
export LD_LIBRARY_PATH=${PYTHONDIR}:${LD_LIBRARY_PATH}
export DYLD_LIBRARY_PATH=${PYTHONDIR}:${DYLD_LIBRARY_PATH}

solves above problem :open_mouth: ??

Cheers, Sergio

NB: my Python version was installed from python.org:

[pb-d-128-141-141-210.cern.ch]:~% ls /Library/Frameworks/Python.framework/Versions/Current  
Headers   Mac       Python    Resources bin       include   lib       share

Sergio,

the problem is likely solved in the second situation b/c the locations given for the libraries of python don’t match those of the binary. In any case, it’s not necessary to set (DY)LD_LIBRARY_PATH for python, as the binary knows how to locate its library (it’s a different matter when using TPython from CINT, as CINT needs to locate the python library).

But check which python and see whether it matches the system one?

Cheers,
Wim

Hi Wim,

thanks for your explanation, although I am not sure to understand…

[sergio-gonzalez-sevillas-macbook-pro.local]:~% which python
/usr/local/bin/python
[sergio-gonzalez-sevillas-macbook-pro.local]:~% ls -ltr  /usr/local/bin/python
lrwxr-xr-x  1 root  wheel  64 Oct 26 16:17 /usr/local/bin/python -> /Library/Frameworks/Python.framework/Versions/Current/bin/python
[sergio-gonzalez-sevillas-macbook-pro.local]:~% ls -ltr /Library/Frameworks/Python.framework/Versions/Current 
lrwxr-xr-x  1 root  admin  3 Oct 26 16:21 /Library/Frameworks/Python.framework/Versions/Current -> 2.5
[sergio-gonzalez-sevillas-macbook-pro.local]:~% ls -ltr /Library/Frameworks/Python.framework/Versions/2.5    
total 16000
drwxrwxr-x   3 root  admin      102 Dec 23  2008 share
-r-xrwxr-x   1 root  admin  8186228 Dec 23  2008 Python
drwxrwxr-x   3 root  admin      102 Dec 23  2008 include
drwxrwxr-x   3 root  admin      102 Dec 23  2008 Mac
drwxrwxr-x  14 root  admin      476 Dec 23  2008 bin
drwxrwxr-x  19 root  admin      646 Dec 23  2008 lib
lrwxr-xr-x   1 root  admin       17 Oct 26 15:58 Headers -> include/python2.5
drwxrwxr-x   6 root  admin      204 Oct 26 15:59 Resources

In my path I made sure /usr/local/bin comes first than /usr/bin, the latter being where the different apple built-in python binaries are installed, the rest of the stuff being located in /System/…:

[sergio-gonzalez-sevillas-macbook-pro.local]:~% ls -ltr /System/Library/Frameworks/Python.framework/Versions
total 8
drwxr-xr-x   8 root  wheel  272 Oct 25 00:47 2.3
drwxr-xr-x  12 root  wheel  408 Oct 25 15:53 2.5
drwxr-xr-x  12 root  wheel  408 Oct 25 15:53 2.6
lrwxr-xr-x   1 root  wheel    3 Oct 25 20:46 Current -> 2.6

On the other hand,if I do not explicitely specify DYLD_LIBRARY_PATH I got the first error posted in this thread.

Thanks and cheers,
Sergio

Sergio,

sorry, I missed that you were using a local version of python. Having a look at the structure, I note that there is no libpython2.5.* in (the equivalent of your) $PYTHONDIR/lib to link with. In my case, that library is in /usr/lib, and would in /usr/local/lib for you. Do you have that path in (DY)LD_LIBRARY_PATH?

Cheers,
Wim