PyRoot doesn't work on PyCharm

Dear all,
I installed Root by Snap (before I tried Conda). PyRoot works well by terminal on my Ubuntu 21.10 but I need to work with PyCharm (version 2021.2.3).
I tried to import pyroot by using Python interpreter but when I try to run my program with this first line of code:
import ROOT
the output of the interpreter is:
ModuleNotFoundError: No module named ‘ROOT’
How can I solve this?
Thank you


_ROOT Version: 6.24/06
_Platform: Ubuntu 21.10
_Compiler: Python


Hello,

For what Python did Snap install ROOT? Did you need to set any PYTHONPATH?

This looks like Pycharm is either not using the same Python installation or it’s missing the setting of ROOT’s PYTHONPATH.

Sorry for not picking this up earlier!

The snap version of ROOT doesn’t place files in any standard system directories due to the nature of snap packages. When you call out to root (or pyroot), you’re actually dropping into a container similiar to Docker, which is almost like running on a virtual machine / remote machine that’s not the same as the host environment.

Some IDE’s (in particular I remember Spyder) throw some unfortunate blockers. In theory, you should be able to set the IDE’s Python interpretter to /snap/bin/pyroot and it could work. Sometimes however I’ve noticed the IDE is too clever for its own good and doesn’t actually let you set it like this. The PyCharm documentation for this appears here and might help you fix this. Configure a Python interpreter | PyCharm

Assuming you can set the interpreter path properly, I wouldn’t expect you need to set the PYTHONPATH variable itself, because the pyroot binary handles that too.

Ultimately I’d recommend you could try using the in built Jupyter Notebook functionality that the snap comes bundled with, you could access it via root --notebook and it appears in the web browser as expected. If this isn’t sufficient, I’d probably recommend that you just consider an alternative installation source (I.E, Conda, given the lack of 21.10 binary distributions at present) which interacts with the native host much better.

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