Problem with using ROOT in PyCharm

I am new to ROOT and also Linux, so please reply to me easy. Thank you.

I chose Python (PyROOT) to work in. I have installed Anaconda and [Conda ROOT] ( I am using PyCharm for programming, but immediately after I created a project I got into a problem with importing classes from PyROOT. PyCharm displays “Unresolved reference ROOT” error every time I try to import anything (TF1, gROOT, TCanvas, etc.), but when I ignore the errors, compile and run the file, there is no problem and it works. It does the job successfully and finishes it as it should.

My question is, if is there any way to solve this and get PyCharm’s code completion working even on ROOT classes. I’ve tried recommendations which I found on this forum (such as recompiling ROOT, adding ‘export’ lines to PyCharm’s startup file and using rootpy - nothing works)

Thank you in advance for helping me.

Best regards,
Jakub Ferenčík

Version: 6.18 / 00
Platform: Linux Ubuntu 18.04.2 / 19.04
IDE: JetBrains PyCharm CE

1 Like

Is the Project Interpreter in PyCharm set to the Python packaged with the conda installation you used to install ROOT?

Yes, it is. As I wrote, the code runs completely fine, but the code completion isn’t working at all.

@Axel do you have an idea how we can help here?

Thanks for posting here, Jakub!

Does the code work when you use it outside PyCharm? Maybe it’s a setup issue with PyCharm? Maybe it doesn’t know about or find PyROOT?


Nothing to do with the setup, but rather that “ROOT” in sys.modules is not a file on disk (it’s an object that’s placed there by, so can not be found, and all classes are loaded lazily, thus not available for tab-completion until used.

Aside, this is why cppyy master uses the cppyy.gbl object for lookups, so cppyy is a normal module, and reimplements __dir__ to allow tab-completion w/o affecting lazy creation.

Thank you for your reply @Axel and @wlav!

As I wrote, the code works even when I run it from PyCharm’s terminal. My last thoughs on that, described exactly @wlav. I was thinking that PyROOT classes are available till after running the python interpreter, and now it had been confirmed.
So, is there any (not ridiculous) way, how to get the code-completion working, or should I forget about it?
Apologize me, I have not understood what cppyy is.

cppyy is what’s underneath experimental pyroot, which can be enabled when rebuilding ROOT from source.

My assumption is that PyCharm uses something like module inspect rather than parsing the python code, i.e. it would import the module and then uses reflection. If it parses the files, then it won’t find what its looking for either way. Although IIRC, PyCharm also collects type info during debug runs for determining (possible) return types, which may well work with the more general dynamic behavior of class creation as well. Not sure whether that’s on by default.

I am now rebuilding ROOT with -Dpyroot_experimental=ON and also -Dgxx14=ON (from ROOT 7).
I will test it and inform you.

Thank you so far for help.

I updated the page - the current way to enable ROOT7 is -DCMAKE_CXX_STANDARD=14