Error while running command 'thisroot.sh'

Hi everyone!

I am really inexperienced regarding root, python and bash, so please try to explain step by step if you can. thanks

I guess this question has already been asked before, but after looking thoroughly for it I couldn’t find it.

I installed root through Homebrew and when I open it on the terminal shell it works fine, but whenever I type the command ‘thisroot.sh’ I always get this output:
/usr/local/bin/thisroot.sh: line 33: ${(%):-%N}: bad substitution

ERROR: must cd where/root/is before calling . bin/thisroot.sh for this version of bash!

/usr/local/bin/thisroot.sh: line 43: return: can only `return’ from a function or sourced script

I do not really understand what it means.

moreover, my main problem is that whenever I try to import root inside a python shell, it always tells me that there is no such module, but both python and root were installed through homebrew and they are both in the same directory. Moreover, I also added the specific path to root in the python shell using the sys.path.insert command, but still python would not let me import root.

Does anyone know how I could fix this issue?

You need to execute:

source /usr/local/bin/thisroot.sh

or:

. /usr/local/bin/thisroot.sh

Thank you very much for your help.

It is really appreciated.

I did it, but still afterwards python tells me there is no module named root.

So do you know how I could successfully import root inside python shell?

Thank you again

Try root-config --features and see if you have “python” inside.

I do, I think.

This is the output I get:
asimage astiff builtin_afterimage builtin_davix builtin_freetype builtin_ftgl builtin_gl2ps builtin_glew builtin_llvm builtin_clang builtin_vdt builtin_xxhash cling cocoa cxx11 davix exceptions explicitlink fftw3 fortran gdml genvector gnuinstall http imt libcxx mathmore minuit2 opengl pch python roofit shared sqlite ssl thread tmva tmva-cpu vdt xml xrootd

So, in [i]python try:

from ROOT import TCanvas
TCanvas("c")

This is the output:
*** Break *** segmentation violation

[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)

[/usr/lib/system/libsystem_c.dylib] tzsetwall_basic (no debug info)

[/usr/local/Cellar/root/6.14.02/lib/root/libPyROOT.so] _GLOBAL__sub_I_TMemoryRegulator.cxx (no debug info)

[/usr/lib/dyld] ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) (no debug info)

[/usr/lib/dyld] ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) (no debug info)

[/usr/lib/dyld] ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (no debug info)

[/usr/lib/dyld] ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) (no debug info)

[/usr/lib/dyld] ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) (no debug info)

[/usr/lib/dyld] dyld::runInitializers(ImageLoader*) (no debug info)

[/usr/lib/dyld] dlopen (no debug info)

[/usr/lib/system/libdyld.dylib] dlopen (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] _PyImport_GetDynLoadFunc (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] _PyImport_LoadDynamicModule (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] import_submodule (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] load_next (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyImport_ImportModuleLevel (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] builtin___import__ (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyObject_Call (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyEval_CallObjectWithKeywords (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyEval_EvalFrameEx (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyEval_EvalCodeEx (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyEval_EvalCode (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyImport_ExecCodeModuleEx (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] load_source_module (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] import_submodule (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] load_next (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyImport_ImportModuleLevel (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] builtin___import__ (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyObject_Call (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyEval_CallObjectWithKeywords (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyEval_EvalFrameEx (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyEval_EvalCodeEx (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyEval_EvalCode (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyImport_ExecCodeModuleEx (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] load_source_module (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] import_submodule (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] load_next (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyImport_ImportModuleLevel (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] builtin___import__ (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyObject_Call (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyEval_CallObjectWithKeywords (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyEval_EvalFrameEx (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyEval_EvalCodeEx (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyEval_EvalCode (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] run_mod (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyRun_InteractiveOneFlags (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyRun_InteractiveLoopFlags (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] PyRun_AnyFileExFlags (no debug info)

[/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/Python] Py_Main (no debug info)

[/usr/lib/system/libdyld.dylib] start (no debug info)

[<unknown binary>] (no debug info)

Hi @zimmik44,

Can you check the value of your PYTHONPATH variable? Does it contain the ROOT lib directory?

Cheers,

Enric

Hi, since you installed ROOT from Homebrew, are you using Python also from Homebrew? What does which python show?

Hi!

Thank you for the interest. I am not really sure how I could check the value of my PYTHONPATH variable, but I can tell you what I get when I print the sys.path in my python shell.

This is the outcome:
[’’, ‘/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python27.zip’, ‘/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7’, ‘/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin’, ‘/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac’, ‘/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages’, ‘/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk’, ‘/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old’, ‘/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload’, ‘/usr/local/lib/python2.7/site-packages’]

How should I proceed?

Thank you again for your help!

Hi!

Thank you for the interest.

This is the outcome of which python:
/usr/local/bin//python

and this is the outcome of which ROOT:
/usr/local/bin//ROOT

So they are actually in the exact same directory.

What should I do then?

Thank you!

I think I know what’s going on. The default python in Homebrew is python2.7, but their default build of ROOT installs ROOT’s PyROOT module for python 3. Could you try

PYTHONPATH=/usr/local/lib/root python3

and then import ROOT?

Thank you so much, it imported it, that s great!

You really are a life saver.

Do you know if there is any way how I could make this modification permanent so that every time i run a python shell from my terminal, I can directly import ROOT?

Cheers

Thank you. My recommendation is to follow the docs for Homebrew: https://docs.brew.sh/Homebrew-and-Python and what brew info python recommends. In summary, you need to add the following to your bashrc:

export PATH="/usr/local/opt/python/libexec/bin:$PATH"
export PYTHONPATH="$PYTHONPATH:/usr/local/lib/root"

Sorry to bother again.

I have done everything that you advised but I have a new problem now though, which is for some reason I cannot import files into python now which are in a directory in my home directory.

I have tried adding the path of the directory they are in using sys.path.insert() once in the python3 shell, but for some reason, it keeps telling me that it cannot find such files.

Do you have any idea?

Thanks

Hi!

I promise, it is the last time I bother you hahah

do you know if there is a way to use python 2 instead?

because I was given many files that were all written for python2 and therefore are not meant for python3

Thank you

If you want to use ROOT with Python2, have a look at https://formulae.brew.sh/formula/root as towards the bottom there are examples on how to customize the installation. In that case, you may have to adjust the variables I mentioned above when you add to your .bashrc. Cheers,

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