Mac OS 10.9 : Problem with Python

Hi all,

Like many other users I had some problem installing root on the new OS version. The “Git trick” ([url]Locate like command made the trick and things seem to work now.

However I still have a problem with Python. I use the pre build mac version of Python and gcc 4.4.7 installed via MacPorts (I tried the mac prebuilt version first, it leads to the same problem).

Importing ROOT in Python leads to the following error:


[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] 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 "/Users/David/Documents/root/lib/ROOT.py", line 257, in <module>
    _root.gPad         = _ExpandMacroFunction( "TVirtualPad",  "Pad" )
  File "/Users/David/Documents/root/lib/ROOT.py", line 237, in __init__
    c = _root.MakeRootClass( klass )
AttributeError: type object 'string' has no attribute 'c_str'

In ROOT.py, these are the lines that cause the problem :


### special cases for gPad, gVirtualX (are C++ macro's) -------------------------
class _ExpandMacroFunction( object ):
   def __init__( self, klass, func ):
      c = _root.MakeRootClass( klass )
      self.func = getattr( c, func )

   def __getattr__( self, what ):
      return getattr( self.__dict__[ 'func' ](), what )

   def __cmp__( self, other ):
      return cmp( self.func(), other )

   def __len__( self ):
      if self.func():
         return 1
      return 0

_root.gPad         = _ExpandMacroFunction( "TVirtualPad",  "Pad" )
_root.gVirtualX    = _ExpandMacroFunction( "TVirtualX",    "Instance" )
_root.gDirectory   = _ExpandMacroFunction( "TDirectory",   "CurrentDirectory" )
_root.gFile        = _ExpandMacroFunction( "TFile",        "CurrentFile" )
_root.gInterpreter = _ExpandMacroFunction( "TInterpreter", "Instance" )

Any call to _ExpandMacroFunction provokes the error. The comment says “(are C++ macro’s)”, maybe I miss some libraries to make it work.

Does this affect other people ? If not, which version of Python/Gcc do you use ? Any any ideas will be welcomed.

Thanks,
David

[quote=“atomdust”]Hi all,

Like many other users I had some problem installing root on the new OS version. The “Git trick” ([url]Locate like command made the trick and things seem to work now.

However I still have a problem with Python. I use the pre build mac version of Python and gcc 4.4.7 installed via MacPorts (I tried the mac prebuilt version first, it leads to the same problem).

Importing ROOT in Python leads to the following error:


[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] 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 "/Users/David/Documents/root/lib/ROOT.py", line 257, in <module>
    _root.gPad         = _ExpandMacroFunction( "TVirtualPad",  "Pad" )
  File "/Users/David/Documents/root/lib/ROOT.py", line 237, in __init__
    c = _root.MakeRootClass( klass )
AttributeError: type object 'string' has no attribute 'c_str'

In ROOT.py, these are the lines that cause the problem :


### special cases for gPad, gVirtualX (are C++ macro's) -------------------------
class _ExpandMacroFunction( object ):
   def __init__( self, klass, func ):
      c = _root.MakeRootClass( klass )
      self.func = getattr( c, func )

   def __getattr__( self, what ):
      return getattr( self.__dict__[ 'func' ](), what )

   def __cmp__( self, other ):
      return cmp( self.func(), other )

   def __len__( self ):
      if self.func():
         return 1
      return 0

_root.gPad         = _ExpandMacroFunction( "TVirtualPad",  "Pad" )
_root.gVirtualX    = _ExpandMacroFunction( "TVirtualX",    "Instance" )
_root.gDirectory   = _ExpandMacroFunction( "TDirectory",   "CurrentDirectory" )
_root.gFile        = _ExpandMacroFunction( "TFile",        "CurrentFile" )
_root.gInterpreter = _ExpandMacroFunction( "TInterpreter", "Instance" )

Any call to _ExpandMacroFunction provokes the error. The comment says “(are C++ macro’s)”, maybe I miss some libraries to make it work.

Does this affect other people ? If not, which version of Python/Gcc do you use ? Any any ideas will be welcomed.

Thanks,
David[/quote]

I have the same problem and it was also reported on the pyRoot forum. Importing ROOT twice works though who knows how successfully:

>>> import ROOT
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/temp/root/lib/root/ROOT.py", line 257, in <module>
    _root.gPad         = _ExpandMacroFunction( "TVirtualPad",  "Pad" )
  File "/usr/local/temp/root/lib/root/ROOT.py", line 237, in __init__
    c = _root.MakeRootClass( klass )
AttributeError: type object 'string' has no attribute 'c_str'
>>> import ROOT
>>> 

Hi,

Installing the new version v5-34-11 by source now works, but this problem still occurs. I suppose that it comes from a lack of libraries on my computer.

David.

For reference: this is the same issue reported in the PyROOT forum:

Hi,

fixed in v5-34-00-patches. The dictionary for ‘std::string’ is not loaded (and std::string isn’t available in the first place, only ‘string’ which is also a python module, hence that specific error as the module hasn’t a c_str()).

Cheers,
Wim

Hi,

Thanks a lot, everything’s fine !

David

Works for me on 10.9 as well, when is 5.34.12 expected?

[quote=“wlav”]Hi,

fixed in v5-34-00-patches. The dictionary for ‘std::string’ is not loaded (and std::string isn’t available in the first place, only ‘string’ which is also a python module, hence that specific error as the module hasn’t a c_str()).

Cheers,
Wim[/quote]

Hi,
I’m experiencing the same problem, i.e.:
ihulk:~ dinardo$ python test.py
Traceback (most recent call last):
File “test.py”, line 1, in
import ROOT
File “/Users/dinardo/root/lib/ROOT.py”, line 257, in
_root.gPad = _ExpandMacroFunction( “TVirtualPad”, “Pad” )
File “/Users/dinardo/root/lib/ROOT.py”, line 237, in init
c = _root.MakeRootClass( klass )
AttributeError: type object ‘string’ has no attribute ‘c_str’

I’m using Mac OS 10.9
Native Mac python, which is 2.7
And root_v5.34.00.patches compiled by myself with the following options:
./configure macosx64 --enable-cocoa --enable-roofit --enable-minuit2 --enable-python --with-gsl-incdir=/Users/dinardo/GSL_v1.16/include --with-gsl-libdir=/Users/dinardo/GSL_v1.16/lib

The .bash_profile is configured in the following way:

Root setup

export ROOTSYS=/Users/dinardo/root
export PATH=$ROOTSYS/bin:$PATH
export DYLD_LIBRARY_PATH=$ROOTSYS/lib:$DYLD_LIBRARY_PATH

Python setup

For pyglet: export VERSIONER_PYTHON_PREFER_32_BIT=yes

export PYTHONPATH=/Users/dinardo/pyglet:$PYTHONPATH
export PYTHONDIR=/usr/bin/python2.7
export DYLD_LIBRARY_PATH=/usr/lib/python2.7:$DYLD_LIBRARY_PATH
export PYTHONPATH=$ROOTSYS/lib:$PYTHONPATH

Can you please suggest me how to solve the problem ?

Many thanks,

  • Mauro.

Mauro,

v5-34-00-patches is a moving target. Do you have the latest? If not either update or get one of the recent patch releases.

Cheers,
Wim