pythonmacospycharmosx-yosemitepyroot

Pycharm 4 no module named ROOT, when importing a locally installed module (PyROOT), that is working fine from shell on Mac OS X Yosemite


I am trying to set up PyROOT to work with Pycharm 4 on Mac OS X Yosemite.

I have installed ROOT (locally), with the python option enabled, and set up all of the necessary environment paths.

echo $PYTHONPATH
/Users/natalia/Software/root/lib:/Users/natalia/Software/root/bin:/Users/natalia/Software/root

It works just fine from the shell interpreter:

python
Python 2.7.6 (default, Sep  9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>> ROOT.__file__
'/Users/natalia/Software/root/lib/ROOT.pyc'
>>>

In Pycharm I have tried to add these paths to the interpreter using Preferences->Project Interpreter->More->Show paths...

The paths that show there are the following:

file:///Library/Python/2.7/site-packages/pip-6.1.1-py2.7.egg
file:///Users/natalia/Software/root/lib
file:///System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
file:///System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
file:///System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
file:///System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
file:///System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
file:///System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
file:///System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
file:///System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC
file:///Library/Python/2.7/site-packages
file:///Users/natalia/Software/root/bin
file:///Users/natalia/Software/root

I created the following file in Pycharm:

import os
os.system("echo $PYTHONPATH")
import ROOT

When run, it returns this:

Traceback (most recent call last):
/Users/natalia/Software:/Users/natalia/Software/root:/Users/natalia/Work/Projects/untitled
 File "/Users/natalia/Work/Projects/untitled/l.py", line 3, in <module>
    import ROOT
ImportError: No module named ROOT

Notice how this PYTHONPATH that's printed from python in Pycharm doesn't include (for a reason unknown to me) the path that actually includes the ROOT.pyc file, that is: '/Users/natalia/Software/root/lib'

I have also tried doing the dirty trick of

os.system("export PYTHONPATH=$PYTHONPATH:/Users/natalia/Software/root/lib") 

but I found it doesn't actually change the path if I print it afterwards.

I am absolutely confused as to where Pycharm gets the paths from. Any possible solutions would be welcome and greatly appreciated.


Solution

  • You may have figured this out already, but just in case...

    import sys
    sys.path.append('/Applications/Misc/root/lib')
    import ROOT
    print ROOT.TTimeStamp().AsString()
    

    will add that search path to Python (& PyCharm by extension); the snippet gives me the following output in PyCharm:

    /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
    /Users/rrios/PycharmProjects/untitled/dummy.py
    Thu, 02 Jul 2015 01:07:57 UTC +628998000 nsec
    
    Process finished with exit code 0