Trying to use ROOT in VS Code

ROOT Version: root_v6.30.06.win64.vc17.debug
Platform: Windows 11 64-bit
Interpreter: Python 3.11.9 64-bit

Whenever I try to import Root on a python file in VS code I just get a module not found error. I’m not that familiar with VS code so im not sure if I have to put the root file I downloaded [] in the same folder as my .py file. Or if its something in my VS code setting that I have to switch to be able to find it. I’m think I have all the dependencies because it works fine on the x86 cmd prompt. When I run thisroot.bat start python then import Root no error shows. How would I be able to let a python file in VS Code to import it?

In VS code, you might need to change the embedded terminal from ‘powershell’ to ‘cmd’ so that it works.

Also, to automatically call thisroot.bat from within VScode, you might add the call to thisroot.bat to the terminal profile file (.json), see e.g. visual studio code - VSCode: How to run a command after each terminal open? - Stack Overflow

So I actually have to call thisroot.bat first in VS code terminal after I change it to cmd. Then once I do that Im able to run my file in VS code and it would import ROOT? It’s still not working … :frowning:

One you open the embedded terminal, call first vcvarsall.bat (check the x86 native tools shortcut to find where it’s located), and then thisroot.bat
Then call “python”, and then “import ROOT” to see whether the terminal is working.

If that all works, calling python from there should also work.

To automatize the process, you might need to change the settings.json file to do all that automatically as part of your VS profile.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.