Problem with importing Python ROOT on windows

Hello,

I am trying to use ROOT on windows. I ran into a problem with python. I cannot import ROOT python library - just a one liner

import ROOT

shows an error

Traceback (most recent call last):
  File "C:\Programming\root\testTaskPy\main.py", line 1, in <module>
    import ROOT
  File "C:\root_v6.22.02\bin\ROOT.py", line 24, in <module>
    import cppyy
  File "C:\root_v6.22.02\bin\cppyy.py", line 61, in <module>
    import libPyROOT as _backend
ImportError: DLL load failed while importing libPyROOT: The specified module could not be found.

What I did

  • Installed 32 bit python 3.9
  • Added root to PYTHONPATH - specifically both the bin and the lib folders

I assume the problem is somewhere further down the chain as Python correctly tires to import from the root folder.

Any help would be appreciated, thank you!

As a side note I also have a problem with uproot related to this issue: https://developercommunity.visualstudio.com/content/problem/1207405/fmod-after-an-update-to-windows-2004-is-causing-a.html
Though this is probably unrelated to this root forum? Or does anyone here use uproot for root as well?

I’ll check and let you know. In the meanwhile, can you try to call the thisroot.bat script (in the bin folder of ROOT) before starting python, to see if that solves the issue?

Well, I think this is unrelated

So ROOT v6.22.02 should work:

C:\Users\sftnight>build\v6-22-02\bin\thisroot.bat

C:\Users\sftnight>python
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Warning in <TClassTable::Add>: class ROOT::Detail::TTypedIter<class TEnumConstant> already in TClassTable
>>>

Hello, thanks for the reply, unfortunately it did not work - error message is still the same (attached below). I double checked the path. I use 32 bit version of python. C:\Program Files (x86)\Python39-32 The 64 bit one was complaining that libPyRoot was not a valid win32 application or something along those lines. Can provide the full 64 bit error if necessary. Here is the output of the 32:

PS C:\> python --version
Python 3.9.0
PS C:\> .\root_v6.22.02\bin\thisroot.bat
PS C:\> python .\Programming\root\testTaskPy\main.py
Traceback (most recent call last):
  File "C:\Programming\root\testTaskPy\main.py", line 1, in <module>
    import ROOT
  File "C:\root_v6.22.02\bin\ROOT.py", line 24, in <module>
    import cppyy
  File "C:\root_v6.22.02\bin\cppyy.py", line 61, in <module>
    import libPyROOT as _backend
ImportError: DLL load failed while importing libPyROOT: The specified module could not be found.
PS C:\>

Can you try in a regular command prompt?

Still the same thing even in cmd I’m afraid.

C:\>root_v6.22.02\bin\thisroot.bat

C:\>python --version
Python 3.9.0

C:\>python Programming\root\testTaskPy\main.py
Traceback (most recent call last):
  File "C:\Programming\root\testTaskPy\main.py", line 1, in <module>
    import ROOT
  File "C:\root_v6.22.02\bin\ROOT.py", line 24, in <module>
    import cppyy
  File "C:\root_v6.22.02\bin\cppyy.py", line 61, in <module>
    import libPyROOT as _backend
ImportError: DLL load failed while importing libPyROOT: The specified module could not be found.

C:\>

I’ve checked and in my bin folder there are multiple libPyRoot files - dll, pdp, pyd, rootmap, and a libPyRoot_rdict.pcm

OK, then I don’t know, it should work… Can you try exactly what I did:

C:\Users\sftnight>build\v6-22-02\bin\thisroot.bat

C:\Users\sftnight>python
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Warning in <TClassTable::Add>: class ROOT::Detail::TTypedIter<class TEnumConstant> already in TClassTable
>>>

The only difference is the Python version, that might be the issue…

You’re probably right, I’ll download 3.8.3 32 bit and let you know

C:\>root_v6.22.02\bin\thisroot.bat

C:\>python
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct  5 2020, 15:23:07) [MSC v.1927 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\root_v6.22.02\bin\ROOT.py", line 24, in <module>
    import cppyy
  File "C:\root_v6.22.02\bin\cppyy.py", line 61, in <module>
    import libPyROOT as _backend
ImportError: DLL load failed while importing libPyROOT: The specified module could not be found.
>>>

Thank you so much!!! 3.8.3 fixed the problem!

C:\>root_v6.22.02\bin\thisroot.bat

C:\>python
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Warning in <TClassTable::Add>: class ROOT::Detail::TTypedIter<class TEnumConstant> already in TClassTable
>>>
1 Like

Good! And note that a PowerShell script equivalent to thisroot.bat (thisroot.ps1) will be available in the next release of ROOT

1 Like

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