# Trying to use ROOT in VS Code

**URL:** <https://root-forum.cern.ch/t/trying-to-use-root-in-vs-code/59427>\
**Category:** ROOT\
**Created:** [May 22, 2024, 5:32am UTC](https://root-forum.cern.ch/t/trying-to-use-root-in-vs-code/59427 "2024-05-22T05:32:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![g0dmax](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/g0dmax/32/36563_2.png) [@g0dmax](https://root-forum.cern.ch/u/g0dmax)\
**Post date:** [May 22, 2024, 5:32am UTC](https://root-forum.cern.ch/t/trying-to-use-root-in-vs-code/59427/1 "2024-05-22T05:32:38Z")

</div>

_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 [root\_v6.30.06.win64.vc17.debug.zip] 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?

 ![Screenshot 2024-05-21 222529](https://root-forum.cern.ch/uploads/default/original/3X/7/6/767089c7183b6f44cea22d0514ca55a2d0e155e4.png)

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [May 22, 2024, 5:50am UTC](https://root-forum.cern.ch/t/trying-to-use-root-in-vs-code/59427/2 "2024-05-22T05:50:03Z")

</div>

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](https://stackoverflow.com/a/60438403/7471760)

---

<div class="post-metadata">

**Author:** ![g0dmax](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/g0dmax/32/36563_2.png) [@g0dmax](https://root-forum.cern.ch/u/g0dmax)\
**Post date:** [May 23, 2024, 1:02am UTC](https://root-forum.cern.ch/t/trying-to-use-root-in-vs-code/59427/3 "2024-05-23T01:02:28Z")

</div>

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 … ☹

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [May 23, 2024, 7:14am UTC](https://root-forum.cern.ch/t/trying-to-use-root-in-vs-code/59427/4 "2024-05-23T07:14:07Z")

</div>

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 myscript.py 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.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [June 6, 2024, 7:14am UTC](https://root-forum.cern.ch/t/trying-to-use-root-in-vs-code/59427/5 "2024-06-06T07:14:40Z")

</div>

Closed on June 6, 2024, 7:14am UTC

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