How to start root in VSCode

I’m a freshman majoring in physics with some python skills and literally no C/C++ experiences. Have no idea how to use root without typing in my terminal. How can I do so?

Hi @Pipi,

I guess that you already have a ROOT distribution installed, correct me if I’m wrong. As a reminder, ROOT can be used either

  1. from the shell: ROOT prompt (C++)
$ root
root [0] // type here your C++ code or load an external macro file as follows
root [1] .x macro_file.C

Using the .x command will automatically call a function named after the file (i.e., macro_file in the previous example).

  1. from an interactive Python session or Python script (PyROOT):
$ python
>>> import ROOT
>>> # the code for your analysis
  1. or a Jupyter notebook (Python or C++):
$ root --notebook

For VS Code, maybe you will be interested in this blog post: How to run ROOT Macros in VS Code - ROOT.


Thank you for your reply! However, I found my m1 Macbook air could not import ROOT in python. Does these methods work in m1 Mac?

Hi @Pipi,

AFAIK, there should be no problem in using PyROOT on the M1 Mac, but maybe @Axel can confirm? Could you also post here the error you are getting, if any?


Anyway, thank you for your patience :grin:

Hi @Pipi,

Regarding the No module named 'ROOT' Python error, how did you installed ROOT (e.g. Conda build, brew, etc.)? I think PyROOT support should be there, but either the ROOT package is installed for a different Python version (other than 3.8.3 that you show above), or the package cannot be found on the search path for any other reason, e.g. the conda environment has not been activated.
Maybe @etejedor could suggest something here.

The second problem that you show is totally unrelated. The .x command will automatically call a function called after the file, i.e. slit in your case. That error might be triggered if the file was renamed, in which case, the “entry point” of the macro must also be renamed.


If ROOT was installed with conda, just activating the corresponding environment should be enough to be able to import ROOT.

I used homebrew to install ROOT.

WOW, I just found that inside the macro the function name was ‘slits’ while the file name was ‘slit’, LOL. That helps a lot. Thank you again.

Perhaps you could also search the forum for previous answers on how to make this work.


The problem might be that you installed ROOT via homebrew but in the example above you are running import ROOT inside a conda environment. The python in the conda environment won’t know about python modules installed via homebrew.

I GOT IT. :rofl: :joy:

1 Like