I’ve been trying for quite some hours now to get code completition working in my PyCharm IDE.
I can import PyROOT (as well as rootpy), and I can also run scripts within my IDE, there is just no autocomplete for ROOT. At the import statement, I get the hint that “constant variable imported as non constant”.
In a shell, I also have no autocomplete but can use root (e.g. create a histogram and fill it).
I am running Ubuntu 19.10, ROOT 6.18.4, Python 3.7.5, rootpy 1.0.1, Pycharm 2019.3 Professional
PyROOT is a special kind of Python bindings, in the sense that everything is dynamic: no wrapper Python class is pre-generated for a given C++ class. This means that autocomplete can’t work in the usual way, since ROOT just contains a few important attributes that have been pre-inserted, but not the whole set of ROOT classes. Code completion should work though for methods provided by an object, since those are injected when dynamically creating its class.
Thank you for your replies.
Concerning your last sentence, I don’t understand when objects are created. If they are created at run time, I don’t see how this can make the autocomplete work. I have a minimal non working example:
I create the object h1, but I still don’t get any autocomplete in the next lines. Pycharm just suggests the methods I have already used in this script, and without any implementation (parameters and so on). If I understand you correctly, I should get autocomplete at least for TH1D methods after creating h1, but I don’t.
I have already set my LD_LIBRARY_PATH to the head directory of ROOT.py, and have also added the root libraries to my interpreter path.
If you could explain me what you meant, I would really appreciate it.
Thank you very much for your help.
I tried it again, and in the shell I have autocomplete after creating an object, so there it works.
In my IDE PyCharm it does not which I assume is because the script is not run and therefore the objects do not exist yet.
Regarding wlav’s suggestion, could you please explain this to me? What does it mean to customize dir? I am using root 6.18.4, and in my ROOT library folder there are .rootmap files. In my cppyy.py in the ROOT library folder there is no dir though. What do I have to customize, and how?
Or is it hopeless and I should resign to the fact that there will be no autocomplete in my IDE?