# Problem with using ROOT in PyCharm

**URL:** <https://root-forum.cern.ch/t/problem-with-using-root-in-pycharm/36092>\
**Category:** Newbie\
**Tags:** python\
**Created:** [September 19, 2019, 9:34pm UTC](https://root-forum.cern.ch/t/problem-with-using-root-in-pycharm/36092 "2019-09-19T21:34:28Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fely](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/fely/32/19840_2.png) [@Fely](https://root-forum.cern.ch/u/Fely)\
**Post date:** [September 19, 2019, 9:34pm UTC](https://root-forum.cern.ch/t/problem-with-using-root-in-pycharm/36092/1 "2019-09-19T21:34:28Z")

</div>

Hello,  
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**] ([https://anaconda.org/conda-forge/root](https://anaconda.org/conda-forge/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

* * *

---

<div class="post-metadata">

**Author:** ![Reik](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/reik/32/17302_2.png) [@Reik](https://root-forum.cern.ch/u/Reik)\
**Post date:** [September 20, 2019, 2:18am UTC](https://root-forum.cern.ch/t/problem-with-using-root-in-pycharm/36092/2 "2019-09-20T02:18:48Z")

</div>

> [@Fely](#):
>
> **PyCharm** displays “ _Unresolved reference ROOT_ ” error every time I try to import anything (TF1, gROOT, TCanvas, etc.)

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

---

<div class="post-metadata">

**Author:** ![Fely](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/fely/32/19840_2.png) [@Fely](https://root-forum.cern.ch/u/Fely)\
**Post date:** [September 20, 2019, 4:47am UTC](https://root-forum.cern.ch/t/problem-with-using-root-in-pycharm/36092/3 "2019-09-20T04:47:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![oshadura](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/oshadura/32/14460_2.png) [@oshadura](https://root-forum.cern.ch/u/oshadura)\
**Post date:** [September 20, 2019, 3:03pm UTC](https://root-forum.cern.ch/t/problem-with-using-root-in-pycharm/36092/4 "2019-09-20T15:03:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [September 20, 2019, 9:00pm UTC](https://root-forum.cern.ch/t/problem-with-using-root-in-pycharm/36092/5 "2019-09-20T21:00:42Z")

</div>

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?

Axel

---

<div class="post-metadata">

**Author:** ![wlav](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/w/f07891/32.png) [@wlav](https://root-forum.cern.ch/u/wlav)\
**Post date:** [September 21, 2019, 7:00pm UTC](https://root-forum.cern.ch/t/problem-with-using-root-in-pycharm/36092/6 "2019-09-21T19:00:36Z")

</div>

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 ROOT.py), 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.

---

<div class="post-metadata">

**Author:** ![Fely](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/fely/32/19840_2.png) [@Fely](https://root-forum.cern.ch/u/Fely)\
**Post date:** [September 21, 2019, 11:21pm UTC](https://root-forum.cern.ch/t/problem-with-using-root-in-pycharm/36092/7 "2019-09-21T23:21:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![wlav](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/w/f07891/32.png) [@wlav](https://root-forum.cern.ch/u/wlav)\
**Post date:** [September 22, 2019, 4:40pm UTC](https://root-forum.cern.ch/t/problem-with-using-root-in-pycharm/36092/8 "2019-09-22T16:40:06Z")

</div>

`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.

---

<div class="post-metadata">

**Author:** ![Fely](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/fely/32/19840_2.png) [@Fely](https://root-forum.cern.ch/u/Fely)\
**Post date:** [September 23, 2019, 2:19pm UTC](https://root-forum.cern.ch/t/problem-with-using-root-in-pycharm/36092/9 "2019-09-23T14:19:28Z")

</div>

I am now rebuilding ROOT with `-Dpyroot_experimental=ON` and also `-Dgxx14=ON` (from [ROOT 7](https://root.cern.ch/root-7)).  
I will test it and inform you.

Thank you so far for help.

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [September 28, 2019, 12:21pm UTC](https://root-forum.cern.ch/t/problem-with-using-root-in-pycharm/36092/10 "2019-09-28T12:21:50Z")

</div>

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