# Mac OS 10.9 : Problem with Python

**URL:** <https://root-forum.cern.ch/t/mac-os-10-9-problem-with-python/16826>\
**Category:** ROOT\
**Created:** [October 30, 2013, 5:49am UTC](https://root-forum.cern.ch/t/mac-os-10-9-problem-with-python/16826 "2013-10-30T05:49:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![atomdust](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@atomdust](https://root-forum.cern.ch/u/atomdust)\
**Post date:** [October 30, 2013, 5:49am UTC](https://root-forum.cern.ch/t/mac-os-10-9-problem-with-python/16826/1 "2013-10-30T05:49:44Z")

</div>

Hi all,

Like many other users I had some problem installing root on the new OS version. The “Git trick” ([url][Locate like command](https://root-forum.cern.ch/t/locate-like-command/65/1) 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:

```auto

[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](http://ROOT.py), these are the lines that cause the problem :

```auto

### 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

---

<div class="post-metadata">

**Author:** ![marktobin1976](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/d07c76/32.png) [@marktobin1976](https://root-forum.cern.ch/u/marktobin1976)\
**Post date:** [October 30, 2013, 2:24pm UTC](https://root-forum.cern.ch/t/mac-os-10-9-problem-with-python/16826/2 "2013-10-30T14:24:29Z")

</div>

[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](https://root-forum.cern.ch/t/locate-like-command/65/1) 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:

```auto

[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](http://ROOT.py), these are the lines that cause the problem :

```auto

### 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:

```auto
>>> 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
>>> 
```

---

<div class="post-metadata">

**Author:** ![atomdust](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@atomdust](https://root-forum.cern.ch/u/atomdust)\
**Post date:** [November 1, 2013, 1:08pm UTC](https://root-forum.cern.ch/t/mac-os-10-9-problem-with-python/16826/3 "2013-11-01T13:08:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![deil](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/deil/32/11212_2.png) [@deil](https://root-forum.cern.ch/u/deil)\
**Post date:** [November 3, 2013, 3:15pm UTC](https://root-forum.cern.ch/t/mac-os-10-9-problem-with-python/16826/4 "2013-11-03T15:15:43Z")

</div>

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

> [@pyRoot on OS X Maverick](https://root-forum.cern.ch/t/pyroot-on-os-x-maverick/16820/3):
>
> This issue is still present in ROOT v5-34-11 on OS X 10.9. In IPython the error looks like this: [gist.github.com/cdeil/7291259](https://gist.github.com/cdeil/7291259)

---

<div class="post-metadata">

**Author:** ![wlav](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/w/f07891/32.png) [@wlav](https://root-forum.cern.ch/u/wlav)\
**Post date:** [November 3, 2013, 11:06pm UTC](https://root-forum.cern.ch/t/mac-os-10-9-problem-with-python/16826/5 "2013-11-03T23:06:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![atomdust](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@atomdust](https://root-forum.cern.ch/u/atomdust)\
**Post date:** [November 4, 2013, 10:30am UTC](https://root-forum.cern.ch/t/mac-os-10-9-problem-with-python/16826/6 "2013-11-04T10:30:14Z")

</div>

Hi,

Thanks a lot, everything’s fine !

David

---

<div class="post-metadata">

**Author:** ![mzeman](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mzeman/32/11279_2.png) [@mzeman](https://root-forum.cern.ch/u/mzeman)\
**Post date:** [November 10, 2013, 1:21pm UTC](https://root-forum.cern.ch/t/mac-os-10-9-problem-with-python/16826/7 "2013-11-10T13:21:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mauroroot](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/7c8e57/32.png) [@mauroroot](https://root-forum.cern.ch/u/mauroroot)\
**Post date:** [November 30, 2013, 11:38am UTC](https://root-forum.cern.ch/t/mac-os-10-9-problem-with-python/16826/8 "2013-11-30T11:38:32Z")

</div>

[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](http://test.py)  
Traceback (most recent call last):  
File “[test.py](http://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.

---

<div class="post-metadata">

**Author:** ![wlav](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/w/f07891/32.png) [@wlav](https://root-forum.cern.ch/u/wlav)\
**Post date:** [December 3, 2013, 6:37pm UTC](https://root-forum.cern.ch/t/mac-os-10-9-problem-with-python/16826/9 "2013-12-03T18:37:22Z")

</div>

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
