Read .root files with Python on Windows

Hi, there is again something I am doing wrong. Now if I type “root” from a simple cmd I get the output

 'root' is not recognized as an internal or external command,
operable program or batch file.

but if I do the same from a x86 native cross tool comand, prompt then everything works.

the same for improting it in python…

C:\Users\Giammarco>python
Python 3.8.3 (default, Jul  2 2020, 17:28:51) [MSC v.1916 32 bit (Intel)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import root
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'root'
>>>

This is a problem for my VScode IDE, because when I call
import root as ROOT
I get the console output

Traceback (most recent call last):
  File "c:\Users\Giammarco\Desktop\TESTVS19\tets.py", line 3, in <module>
    import root as ROOT
ModuleNotFoundError: No module named 'root'

Any ideas?

root on Windows is still a nightmare…

As I already said, you must call thisroot.bat before running root, and root must run in a x86 Native Tools Command Prompt for VS 2019, or call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat" from a regular command prompt, or properly set the necessary Visual C++ environment variables. And from VS Code you probably have to set the proper environment. And root on Windows is working well if you follow the instructions and if you understand how the environment variables work, which has nothing to do with ROOT…

I am calling thisroot.bat from the x86 prompt, but previously this would have set the right variables in order to call root from a general cmd. Are you sugesting I should call thisroot.bat everytime before running root? This was not the case with my previous 5.34 with VS17.

properly set the necessary Visual C++ environment variables? I followed the standard suggested procedure from VS19 instalaltion wizard. Is there anything more to do?

I meant the integration of root on VS is still a nightmare. ROOT per se is rocking.

ROOT v5.34 didn’t require Visual C++ to be installed at all. Now ROOT 6 has a JIT compiler and it need the C++ header files from the same version of Visual C++ than the one used to build ROOT. And you only need to call thisroot.bat for curent command prompt session, and it will be valid for this session only.

Those environment variables are set for the Command Prompt for VS 2019, not globally. if you need them elsewhere (e.g. in a standard Windows command prompt), then you need either to call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat" or to manually set them.

I’m not sure to understand what you’re talking about… Are you talking about the Visual Studio IDE or the VS Code Editor?

I am getting this as a prompt. I am using 32-bit Python, version 3.9.2 and version 6.22/06 version ROOT on windows. Please help.

C:\root_v6.22.06>cd bin
C:\root_v6.22.06\bin>thisroot.bat
C:\root_v6.22.06\bin>cd…
C:\root_v6.22.06>cd store
C:\root_v6.22.06\store>python
Python 3.9.2 (tags/v3.9.2:1a79785, Feb 19 2021, 13:30:23) [MSC v.1928 32 bit (Intel)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.

import math
import ROOT
Traceback (most recent call last):
File “”, line 1, in
File “C:\root_v6.22.06\bin\ROOT.py”, line 24, in
import cppyy
File “C:\root_v6.22.06\bin\cppyy.py”, line 61, in
import libPyROOT as _backend
ImportError: DLL load failed while importing libPyROOT: The specified module could not be found.

Please don’t reply to an old topic, but open a new one instead. And for your question, see Using PyRoot on Windows 10