Unable to get Root from Conda to start using pyroot for python scripts

ROOT Version: not yet installed
Platform: Windows

Hello,

I’m getting started with ROOT and I’m looking to use it with python for my work. But I can’t seem to install it in a wat that it could be used for python. I tried basically all the variations of install -c conda-forge root and Anaconda doesn’t seem able to locate the packages. I get the following error:

PackagesNotFoundError: The following packages are not available from current channels:

  • root

From what I’ve seen, everyone seemed able to get Root via this method and I feel a bit lost. Any help would be appreciated.


Welcome to the ROOT Forum!
AFAIK, ROOT is not available via conda on Windows. You have to download a pre-compiled binary or build it from source.

So I already have root installed on my computer and it works separately from python. I’ve been trying to import root in a python application and it doesn’t work. Both python and root work perfectly in a separate manner but once I import root in python, it tells me that no module is named ‘root’.

I’m working with vscode if that matters.

Did you call root\bin\thisroot.bat before starting your Python session?
And make sure you use the same version of Python than ROOT (root-config --python-version)

Yes both are x64 and I have called thisrrot.bat before the session. the error keeps coming …

Can you copy and paste your session here together with the output of echo %ROOTSYS%? Something like:

C:\root-dev\git\roottest>echo %ROOTSYS%
C:\root-dev\build\x64\debug

C:\root-dev\git\roottest>python
Python 3.11.4 (tags/v3.11.4:d2340ef, Jun  7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>>

Something like this:

C:\Users\Admin>echo %ROOTSYS%
%ROOTSYS%

C:\Users\Admin>python
Python 3.11.7 (tags/v3.11.7:fa7a6f2, Dec  4 2023, 19:24:49) [MSC v.1937 64 bit (AMD64)] 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'
>>>

So you didn’t call root\bin\thisroot.bat

I’m getting this when I call thisrrot.bat before

C:\Users\Admin> C:\Users\Admin\root_v6.30.02\bin\thisroot.bat

C:\Users\Admin>%ROOTSYS%
'C:\Users\Admin\root_v6.30.02' is not recognized as an internal or external command,
operable program or batch file.

You forgot echo… Try again with:

C:\Users\Admin> C:\Users\Admin\root_v6.30.02\bin\thisroot.bat

C:\Users\Admin>echo %ROOTSYS%

And then you can start Python and import ROOT

I’m so sorry.

C:\Users\Admin>echo %ROOTSYS%
C:\Users\Admin\root_v6.30.02

and now I’m getting this new error:

 C:\Users\Admin>python
Python 3.11.7 (tags/v3.11.7:fa7a6f2, Dec  4 2023, 19:24:49) [MSC v.1937 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Fatal in <TROOT::InitInterpreter>: cannot load library The specified module could not be found.

OK, I see you’re using Python 3.11, and as you can see, the pre-built binary uses Python 3.8:

C:\root-dev\rootdev\test>root-config --python-version
 3.8.10

So it won’t work. You have to either use Python 3.8, or build ROOT from source with a newer version of Python.

But when I personally run this, I get:

C:\Users\Admin>root-config --python-version
3.11.2

C:\Users\Admin>

So it should be ok since I’m using the same version of python, no?

I think so