How to use PyROOT on Windows

Hello,
I am trying to use ROOT in python on Windows 7. I installed python 2.7.1, and ROOT 5.28.00 (prebuilt Windows binaries for both). Per instructions on the ROOT website (root.cern.ch/drupal/content/how- … nterpreter), I set the following environment variables as suggested:

set PATH=%ROOTSYS%/bin;%PATH%
set PYTHONPATH=%ROOTSYS%/bin;%PYTHONPATH%

However, when I try to import ROOT from within python, I get an error saying no ROOT module is found. I can’t run any of the python demos either.

What am I doing wrong? Do I need to compile ROOT from scratch to be able to use ROOT classes from within python? Is python support not available in the prebuilt windows binaries? Most likely I am missing something obvious here.

Many thanks for your help.

-Arun

Arun,

in python, you can look at sys.path (“import sys; print sys.path”) to see whether the paths are properly picked up. It makes a difference (in back- v.s. forward- slashes) whether you use a version of python build for windows, or the cygwin ones. Other than that, I thought that the downloadable binaries are build for p2.6.5.

Cheers,
Wim

Hi Wim,
When I print sys.path in the python gui, I get the following:

[‘C:\Python27\Lib\idlelib’, ‘C:\root\bin’, ‘C:\Python27\ %PYTHONPATH%’, ‘C:\Windows\system32\python27.zip’, ‘C:\Python27\DLLs’, ‘C:\Python27\lib’, ‘C:\Python27\lib\plat-win’, ‘C:\Python27\lib\lib-tk’, ‘C:\Python27’, ‘C:\Python27\lib\site-packages’]

Does some obvious error stick out here ?

Thanks.
-Arun

Arun,

assuming that $ROOTSYS = C:\root that should be okay. (And assuming that you build ROOT locally with that version of python.) Does the directory C:\root\bin contain ROOT.py and libROOT.pyd?

Cheers,
Wim

No, C:\root\bin does not contain ROOT.py and libROOT.pyd.

The only python file I see there is PyCintex.py.

And, I did not build root locally. I just downloaded the windows binary for ROOT 5.28.00. That was part of my original question – is it necessary to build ROOT from source with certain specific configuration options o be able to use it within python? I would have though python support should be automatic, even for the binaries, and one of your posts in this thread seemed to suggest that?

Many Thanks.
-Arun

Arun,

as said, the downloadable binaries are going to require p2.6.5, not p2.7. But even that still isn’t going to help unless ROOT.py and libROOT.pyd can be located … I’m not all that familiar with Windows and do not currently have access to a Windows box. Are ROOT.py and libPyROOT.pyd in $ROOTSYS/lib?

Cheers,
Wim

Hi Wim,
Sorry I couldn’t reply earlier.

No, I don't see ROOT.py and libPyROOT.pyd in $ROOTSYS/lib. Should they have been there in the prebuilt version?

-Arun

I’ve had the same problem.
Seems like those prebuilt (*.msi) packages are broken and do not contain the necessary files for PyROOT.
What I did was simply download the .tar.gz ones and replace the contents of my ROOT installation directory with those.

Thanks. Hopefully this will be fixed in the next release.

Hello from 2017! Problem is still here :frowning:

Hello from 2021, Is this problem still here? I need to use pyROOT on a w10 machine :confused:

PyROOT is available with ROOT 6 on Windows:

C:\Users\bellenot\DAQ>python
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>>

Hello Bellenot,

Not for me:

C:\Users\M. Gonzalez Alvarez>python
Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:04:37) [MSC v.1929 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>
ModuleNotFoundError: No module named 'ROOT'

My ROOT version is 6.24/00. Can you tell me please which version of ROOT are you using? In fact, the issue may be caused by the ROOT installation, which encourages me even more to ask you the version you are using :slight_smile:

Thank you,
Dani

6.25/01, but it doesn’t matter, it works with 6.24/00 as well. I just downloaded the binaries and tried:

C:\Users\bellenot\Downloads>root\bin\thisroot.bat

C:\Users\bellenot\Downloads>root
   ------------------------------------------------------------------
  | Welcome to ROOT 6.24/00                        https://root.cern |
  | (c) 1995-2021, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for win32 on Apr 14 2021, 14:33:50                         |
  | From tags/v6-24-00@v6-24-00                                      |
  | With MSVC 19.23.28107.0                                          |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

root [0] .q

C:\Users\bellenot\Downloads>python
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>>

Thank you Bellenot, that confirms that the issue is with my root6 on w10. I also found another post having the same issue of me (Looks like I have to abandon Root on Windows), so this may mean that I should continue with my virtual machine with Linux and fine :grinning_face_with_smiling_eyes:.

Thank you so much for your help bellenot, it was useful to me and I am sure it will also be to many users :))))

Are you sure? Did you call thisroot.bat before to start Python? It’s also maybe your version of Python which is not compatible (ROOT is 32 bit)

Hello,

As you can see below, the call of the .bat file was done properly

C:\Users\M. Gonzalez Alvarez\Downloads>root\bin\thisroot.bat

But then I can not open root properly:

C:\Users\M. Gonzalez Alvarez>root
RegOpenKeyEx(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\$VERSION\InstallationFolder): returned 2: The system cannot find the file specified.
RegOpenKeyEx(HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Kits\Installed Roots\KitsRoot10): returned 2: The system cannot find the file specified.
input_line_1:1:10: fatal error: 'new' file not found
#include <new>
         ^~~~~
Replaced symbol atexit cannot be found in JIT!
Replaced symbol at_quick_exit cannot be found in JIT!
Replaced symbol __dllonexit cannot be found in JIT!
Replaced symbol _onexit cannot be found in JIT!
input_line_3:37:10: fatal error: 'string' file not found
#include <string>
         ^~~~~~~~
   ------------------------------------------------------------------
  | Welcome to ROOT 6.24/00                        https://root.cern |
  | (c) 1995-2021, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for win32 on Apr 14 2021, 14:33:50                         |
  | From tags/v6-24-00@v6-24-00                                      |
  | With MSVC 19.23.28107.0                                          |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

input_line_7:1:10: fatal error: 'iostream' file not found
#include <iostream>

Still, root opens, but if typing something such as new TBrowser, it does not work:

root [0] new TBrowser
IncrementalExecutor::executeFunction: symbol '?gCling@runtime@cling@@3PAVInterpreter@2@A' unresolved while linking [cling interface function]!
You are probably missing the definition of class cling::Interpreter * cling::runtime::gCling
Maybe you need to load the corresponding shared library?
root [1]

So, I assume this is the reason why import ROOT does not work, somehow ROOT is not correctly installed. I only downloaded the .zip, and did what you do.

I have installed Python 32 bits since ROOT is 32 bits, but my problem seems to be related with ROOT instead.

So first, as mentioned in the Important installation notes:

  • Do not untar in a directory with a name containing blank characters.

So C:\Users\M. Gonzalez Alvarez\ will not work.
Then, you need Visual Studio to be installed on your system, otherwise the interpreter will not find the c++ header files (as you can see).

I am sorry, I did not notice that about the empty spaces.

However, I have now used another directory without empty spaces:

C:\Users\Public>root_v6.24.00.win32.vc16\root\bin\thisroot.bat

And, again, the bat files is properly called but when typing root the same issue appears.

I have Microsoft Studio Community 2019 installed (root 6.24 requires Windows Visual Studio 2019), so that should be fine (community version simply because that version is free :stuck_out_tongue: ). Could that be the issue, I need another version?

No, I use the same. Can you try to start ROOT from a x86 Native Tools Command Prompt for VS 2019?