I am a new comer to root and even to this field, and installed ROOT version 6.26.10 on my macOS13.0.1 via conda.
I can run some C macros using terminal, however, when I try to run some simple codes using python in the terminal again, it fails.
Here is my code and the file name is root_in_py.py
"
from ROOT import *
h = TH1f(“h”, “Random numbers”, 200, -5, 5)
h.Fill(“gaus”)
c = TCanvas()
h.Draw()
c.Print(“c.pdf”)
"
When I run the file by typing
"
$ python root_in_py.py
"
in my terminal, i got the following error
"
Traceback (most recent call last):
File “/…/root_in_py.py”, line 1, in
from ROOT import *
ModuleNotFoundError: No module named ‘ROOT’
"
I have used the command “root-config --has-pyroot” to check if i have installed pyroot also. It returns a yes to me.
However, I tried to run the code in a python prompt or in jupyter notebook. It works!
So this means that something like this works for you (i.e. no error is shown)?
$: python -c "import ROOT"
If yes, then it probably means you are not using the same Python executable when running your script. Make sure you use one unique environment with the same Python executable for everything you do with ROOT, from installing it to using it. Also, do not mix different package managers: you mentioned you installed via conda, so I guess you are making sure you are always activating the conda environment that you used to install ROOT before running the script.
But I am so sorry that I forgot to mention the following situation.
Yes, I am always activating the conda environment that i used to install ROOT before running the script. When i run some C macros in that environment, everything is fine.
However, in the same environment, when i run
$ python root_in_py.py
the terminal keeps processing, and nothing is shown. It just keep processing and processing without any error messages or any outcomes.
Also, the above error msg i shown
Traceback (most recent call last):
File “/…/root_in_py.py”, line 1, in 〈module〉
from ROOT import *
ModuleNotFoundError: No module named ‘ROOT’
is received when i run the same command in my base environment.
Yes, i can run the code in jupyter notebook or python prompt and get the desried outcome without error.
Thanks for this comment. I have run this command after activating the environment and no error is shown.
I have checked the python version of my conda and of my environment, and also my base environment. Both my conda and my base environment use python 3.9.12, however, the environment i used to install ROOT uses python 3.11.0 .
So I guess that s the problem you have pointed out?