import ROOT: no module found -- How to add custom modules to PyCharm's project interpreter



I am using the ROOT data analysis framework:

I would like for PyCharm to be able to recognize my installation of ROOT so that I can run my code and debug within PyCharm. How would I go about this? I am able to see how to create virtual environments and install modules through PyPi, but ROOT is not offered through a package manager and must be built through CMake. If I open a terminal I can import ROOT just fine:

Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>> ROOT.__file__

if possible I would like code completion to work as well... I found this post but it does not offer any additional help:

Comment actions Permalink


Have you tried adding it that way

How did you install it to your system interpreter?

Comment actions Permalink

Thank you, now my code will properly run and the error for "import ROOT" is now gone. However, if I try doing something like "from ROOT import TH1F" PyCharm tells me that TH1F is not found in However, the code will still run whether I do the import like this or do ROOT.TH1F when I am creating this object. I also do not have any code completion.


I believe loads the shared object library libPyROOT,so which contains all of the bindings for the interpreter. Here's what I've been able to find:

"The top level Python module is This module imports the extension module [.dll] and does a similar initialization as the ROOT application (i.e. loading common libraries, defining a number of globals, starting a thread to handle GUI events, etc.). This is the main entry point for any Python script using the ROOT classes."

Comment actions Permalink


Which directories did you add to Interpreter Paths?
From what I can see, there is no TH1F in and also no __init__ files to make an interface for directories and modules.

Maybe it's because I haven't finished building it yet...

Comment actions Permalink

I only added the directory that the path $PYTHONPATH is linked to: "/home/aj/root/lib". I think "" or "cppyy.pyc" might be what is doing this magic. "" is imported in and it seems to do the loading of, which I'm guessing is how the python interpreter interfaces all of the C++ classes (TH1F for example).

Comment actions Permalink

Oh, I see. 
In this case, PyCharm cannot do anything about it to provide code completion since those classes/methods are generated dynamically in runtime and not by only using python modules.

Comment actions Permalink

Ah, makes sense. Thank you very much for your time and help!


Please sign in to leave a comment.