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

Hi Folks,
I am trying to Configure PyROOT in order to work with Pycharm 4 on Mac OS X Yosemite. so, I have installed ROOT (locally), by enabling the python option, 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

And 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

and then 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 totally confused as to where Pycharm gets the paths from?? Any possible solutions would be welcome and greatly appreciated.

Thanks & Regards
Python Programmer

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

runs a sub-shell where the path gets modified, it can not affect the current process, nor can os.environ or os.putenv.

If you want to modify “PYTHONPATH” dynamically for the current proces, then change sys.path.

Beyond that, I’m not familiar with Pycharm. Just like to add that cppyy master has a far more functional implementation of __dir__ then does the version that lives under PyROOT. This will help with code completion in any IDE.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.