ROOT not connecting to python ("module libcppyy could not be found")


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.32.02
Platform: Windows 11
Compiler: cl.exe (I think)


Hello everyone, I hope you are doing well.
This is my first time using ROOT and I am currently trying to set it up and get it working. I am going to provide a lot of information in hopes that this problem is solved faster so, please, bear with me.

My Problem:
Once I’ve started ROOT using C\path\to\root\bin\thisroot.bat in x64 Native Tools Command Prompt for VS 2022, and then I try to do import ROOT in python, I receive this error:

>>> import ROOT
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\CERN ROOT\root\bin\ROOT\__init__.py", line 25, in <module>
    import cppyy
  File "C:\CERN ROOT\root\bin\cppyy\__init__.py", line 81, in <module>
    from ._cpython_cppyy import *
  File "C:\CERN ROOT\root\bin\cppyy\_cpython_cppyy.py", line 22, in <module>
    import libcppyy as _backend
ImportError: DLL load failed while importing libcppyy: The specified module could not be found.

So for some reason, the program cannot find the file libcppyy.

How I set up ROOT
So now I’m going to talk about how I went about setting up ROOT, in case someone believes they have a better way of setting it up.

I downloaded the pre-compiled binary distribution on the install page (I specifically installed root_v6.32.02win64.vc17.zip)

I believe I have also downloaded all the required dependencies: CMake (even though I haven’t done anything with it, will say more about that further down), Microsoft Visual C++ & Desktop Development with C++, and Python (Python 3.12.4)

I then extracted the root zip file into a file in my C drive.
I think I’ve set up all the environment variables correctly:

  • User Path environment variable contains both C:\path\to\root\bin and C:\path\to\root\lib.
  • ROOTSYS variable to C:\path\to\root
  • PYTHONPATH variable to C:\path\to\root\bin and C:\path\to\root\lib

Now, I’m pretty sure ROOT itself works. I can run root, and use C++ commands to create a graph. It’s just when I run python and try to import ROOT, it fails.

What I haven’t tried

  • So I have installed CMake, however I haven’t set it up or added any variables to it because, following the method I did, it didn’t seem to require it?
  • In some places I’ve seen people say that they had to downgrade a python version for it to work. Maybe 3.12 is too new?
  • As you saw I didn’t install ROOT from the github page, but I’ve seen some instructions saying to do it from there.

Thank you so much for taking the time to read this, I’m so sorry that it ended up being so long. Any help would be greatly appreciated.

Hi @AlexanDUHH,

Thanks for your question and welcome to the forum.

Let me add @bellenot in the loop.

Thanks,
Dev

Hi @AlexanDUHH , you must use the same version of Python than the one used by ROOT. You can use root-config --python-version to see which one (3.11. IIRC)

The python bindings work and graphs are being created!
However, slight problem: when I create the graph and try to interact with it, the window for the graph switches to “(not responding)”. Like so:

I’m not sure what might be causing this.

I am able to start ROOT in command prompt / VS2022, type in some C++ code and create a graph that I can interact with, and that doesn’t crash. So the graphs are able to be created normally, but using the python bindings may be messing something up?

And thank you very much for your help I really appreciate it!

Right, this is a known issue on Windows, the only workaround I can propose for now is to use something like:

import time
while not ROOT.gSystem.ProcessEvents():
    time.sleep(0.02)

in order to allow ROOT to process the events

Brilliant! That works in the command prompt / visual studio 2022 when it put it in a method, then call that method.

One final question, is it possible to create a graph in a python script/file? When I’ve tried to do this the graph canvas appears blank and when I try to interact with it, it changes to “not responding”.
Is there a way to fix this?

Thank you for all your responses so far!

1 Like

see tutorials\pyroot\graph.py