Root installation issue

ROOT Version: root_v6.30.06
Platform: Windows
Compiler: Visual Studio Code


I completed all of the steps to download all of the dependencies and then downloaded the latest version of root. Updated the environment variables to include “thisroot.sh” and “thisroot.bat” (I wasn’t sure which one was right so both were added) , and am able to run “root” in the terminal. However, I cannot import ROOT in my code. I still get the “ModuleNotFoundError”. Could it be a missing python binding? Could someone please help me troubleshoot the problem?

Hi,

Are you able to boot ROOT? How do you get this error?
@bellenot

Cheers,
Danilo

Hi,
Yes, I can run “root” in the terminal. The error arises when I try “import ROOT” with my python script.
The error is “ModuleNotFoundError: No module named ‘ROOT’”.
Just for reference about the python version:
$root-config --python-version
3.11.7

$python
Python 3.11.7 | packaged by Anaconda, Inc. | (main, Dec 15 2023,
18:05:47) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
So, I think the python version can be ruled out for this issue.

Thanks for the quick reponse

could you try the following?

import sys
sys.path.append("C:\yourROOTfolder\lib") # Change path to wherever libcppyy is located in your installation folders
import ROOT

It worked. Thank you so much.

Is this the only way to get to make the “ROOT” module accessible? And is running thisroot.bat supposed to accomplish that?

Thanks again!

Yeah, thisroot.bat should have achieved that, but somehow it didn’t work either for me and I had to add the path via sys. I do not know why it’s failing. Maybe @bellenot knows.

I see I see. Thanks for the fix.

Weird, on Windows, the Python libraries are supposed to be in the bin directory, not in lib. I’ll check

I cannot reproduce the issue. thisroot.bat properly sets the environment variables:

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

C:\Users\bellenot\Downloads\root>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
>>>

Hmm maybe it was because of running from a Powershell instead of a CMD shell.

(The other less likely explanation might be when having multiple Python versions installed in the system, calling C:\Programs\python3.11 might ignore PYTHONPATH. )

Right, I’ll investigate

Hi I’m having the same issue on VS code.
I’ve installed everything thats needed and unarchived the root folder. I tried to do the import sys and append method provided above but its still not working. I have the same Root Version, Platform, and Compiler as the original poster of this thread.

When running with VS code embedded terminal, try switching from “powershell” to “cmd”. I did that and it solved it for me.
(I called first vcvarsall.bat as it’s done when you start x64 native tools)

oh we have to call thisroot.bat first then its able to be imported?

I didn’t append the path through lib . I still used bat. It is strange however how running the batch file in cmd works but not in powershell. To be honest, I dont really know the difference between them.

Probably some of the commands used here: root/config/thisroot.bat at master · root-project/root · GitHub
are not valid for Powershell.

@bellenot would it be possible to provide a thisroot.ps1 script alongside with the thisroot.bat one?

I guess so. I’ll check

I just checked the binary distribution and there is already a thisroot.ps1

# Execute this script to set up the ROOT environment variables in Powershell.
#
# Author: Bertrand Bellenot, 17/11/2020

$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
$ROOTSYS = split-path -parent (get-item $scriptPath)
$env:PATH = $ROOTSYS + '\bin;' + $env:PATH
$env:CMAKE_PREFIX_PATH = $ROOTSYS + ';' + $env:CMAKE_PREFIX_PATH
$env:PYTHONPATH = $ROOTSYS + '\bin;' + $env:PYTHONPATH
$env:CLING_STANDARD_PCH = "none"
1 Like

Thanks for that info!

I confirm that it works on VS Code now with powershell!

I had no idea, so I opened a PR to update the web documentation.

1 Like