# How to start root in VSCode

**URL:** <https://root-forum.cern.ch/t/how-to-start-root-in-vscode/45833>\
**Category:** Newbie\
**Created:** [July 13, 2021, 2:56pm UTC](https://root-forum.cern.ch/t/how-to-start-root-in-vscode/45833 "2021-07-13T14:56:52Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pipi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/e9bcb4/32.png) [@Pipi](https://root-forum.cern.ch/u/Pipi)\
**Post date:** [July 13, 2021, 2:56pm UTC](https://root-forum.cern.ch/t/how-to-start-root-in-vscode/45833/1 "2021-07-13T14:56:53Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [July 13, 2021, 3:55pm UTC](https://root-forum.cern.ch/t/how-to-start-root-in-vscode/45833/2 "2021-07-13T15:55:15Z")

</div>

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++)

```auto
$ 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):

```auto
$ python
>>> import ROOT
>>> # the code for your analysis

```

1. or a Jupyter notebook (Python or C++):

```auto
$ root --notebook

```

For VS Code, maybe you will be interested in this blog post: [How to run ROOT Macros in VS Code - ROOT](https://root.cern/blog/root-on-vscode/).

Cheers,  
J.

---

<div class="post-metadata">

**Author:** ![Pipi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/e9bcb4/32.png) [@Pipi](https://root-forum.cern.ch/u/Pipi)\
**Post date:** [July 14, 2021, 1:32am UTC](https://root-forum.cern.ch/t/how-to-start-root-in-vscode/45833/3 "2021-07-14T01:32:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [July 14, 2021, 10:37am UTC](https://root-forum.cern.ch/t/how-to-start-root-in-vscode/45833/4 "2021-07-14T10:37:59Z")

</div>

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?

Cheers,  
J.

---

<div class="post-metadata">

**Author:** ![Pipi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/e9bcb4/32.png) [@Pipi](https://root-forum.cern.ch/u/Pipi)\
**Post date:** [July 14, 2021, 11:17am UTC](https://root-forum.cern.ch/t/how-to-start-root-in-vscode/45833/5 "2021-07-14T11:17:47Z")

</div>

![image](https://root-forum.cern.ch/uploads/default/original/3X/4/4/44b0590022420a2a8f3cad338920c763da4d2607.png)

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/a/2/a2f07693b538f9564a9590eef7fa4f856907d97e.jpeg)

---

<div class="post-metadata">

**Author:** ![Pipi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/e9bcb4/32.png) [@Pipi](https://root-forum.cern.ch/u/Pipi)\
**Post date:** [July 14, 2021, 11:25am UTC](https://root-forum.cern.ch/t/how-to-start-root-in-vscode/45833/6 "2021-07-14T11:25:02Z")

</div>

![image](https://root-forum.cern.ch/uploads/default/original/3X/e/6/e6ff9859728c871b853f894014f7a898a53fa1b4.png)

Anyway, thank you for your patience 😁

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [July 14, 2021, 11:34am UTC](https://root-forum.cern.ch/t/how-to-start-root-in-vscode/45833/7 "2021-07-14T11:34:02Z")

</div>

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.

Cheers,  
J.

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [July 14, 2021, 11:55am UTC](https://root-forum.cern.ch/t/how-to-start-root-in-vscode/45833/8 "2021-07-14T11:55:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Pipi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/e9bcb4/32.png) [@Pipi](https://root-forum.cern.ch/u/Pipi)\
**Post date:** [July 14, 2021, 11:58am UTC](https://root-forum.cern.ch/t/how-to-start-root-in-vscode/45833/9 "2021-07-14T11:58:52Z")

</div>

I used homebrew to install ROOT.

---

<div class="post-metadata">

**Author:** ![Pipi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/e9bcb4/32.png) [@Pipi](https://root-forum.cern.ch/u/Pipi)\
**Post date:** [July 14, 2021, 12:04pm UTC](https://root-forum.cern.ch/t/how-to-start-root-in-vscode/45833/10 "2021-07-14T12:04:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jalopezg](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jalopezg/32/25844_2.png) [@jalopezg](https://root-forum.cern.ch/u/jalopezg)\
**Post date:** [July 14, 2021, 12:09pm UTC](https://root-forum.cern.ch/t/how-to-start-root-in-vscode/45833/11 "2021-07-14T12:09:43Z")

</div>

> [@Pipi](#):
>
> I used homebrew to install ROOT.

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

Cheers.

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [July 14, 2021, 12:10pm UTC](https://root-forum.cern.ch/t/how-to-start-root-in-vscode/45833/12 "2021-07-14T12:10:47Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Pipi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/e9bcb4/32.png) [@Pipi](https://root-forum.cern.ch/u/Pipi)\
**Post date:** [July 14, 2021, 12:14pm UTC](https://root-forum.cern.ch/t/how-to-start-root-in-vscode/45833/13 "2021-07-14T12:14:55Z")

</div>

I GOT IT. 🤣 😂
