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.
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?
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:\>
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.
>>>
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
>>>