pyROOT works only with manual execution of thisroot.sh

Hi everyone!
I’ve built the newest version of ROOT (6.18) with cmake;
I have the following lines in my .bashrc file

source path_to_ROOT/root6.18/bin/thisroot.sh
export LD_LIBRARY_PATH="path_to_ROOT/root6.18/lib":$LD_LIBRARY_PATH

so the script “thisroot.sh” should be executed everytime I open a session (and I manually checked it by adding an output string inside thisroot.sh).
I tried importing ROOT as a module for Python 2.7.15. The problem is, when I open Python and import ROOT i get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named ROOT

Then, if I manually execute thisroot.sh (by typing the same line that’s inside my .bashrc file), I manage to import ROOT without any problems and it works fine.
Why are the lines in my .bashrc not enough? Thank you! :slight_smile:

EDIT: I forgot to say that everything else works fine without the need of manually run thisroot.sh

_ROOT Version: 6.18
_Platform: ubuntu 18.04.3 on Windows 10 WSL
Compiler: Not Provided


Hi Lucio,

Couple of things:

  • if you source .../thisroot.sh you don’t need to export LD_LIBRARY_PATH.
  • This is Windows. Which python do you use, is this a WSL python or a Windows one?
  • How do you start python - do you type python at a bash shell prompt? If so, what does env say right before you type python?

Cheers, Axel.

Hi Axel, thank you for the reply!

I originally added “export LD_LIBRARY_PATH…” because otherwise I couldn’t compile the .cpp file that included ROOT’s classes, using the command:

g++ -o executable file.cpp `root-config --cflags --glibs`

adding that line just solved the problem. I tried again following your advice and I found out that now (I’ve just re-built ROOT) I can compile without the export, so I removed that line. I doubt it has something to do with the upgrade of ROOT; instead, I believe I made a mistake the first time I built it! Thanks!

I use python 2.7.15 installed in the WSL environment, and I start it by typing python in my WSL bash!
By comparing the env outputs, before and after manually executing thisroot.sh, I can see that lots of variables (DYLD_LIBRARY_PATH, ROOTSYS, LIBPATH, PYTHONPATH…) change from “home” to “ROOT’s directory”; if you need me to, I can paste the complete outputs!
After manually running thisroot.sh, pyROOT works perfectly!

Thank you :slight_smile:

Are you able to just run root (only sourcing thisroot.sh in .bashrc)?
If not, perhaps you have other login script/s messing with the variables? Check if you have any of these files in your home: .bash_profile, .bash_login, .profile
If so, you can try adding this line:
echo $ROOTSYS
at the end of .bashrc and of each of the others, to see if it was correctly defined by .bashrc and maybe find where it is being changed.

Hi, thank you!
Yes, I’m able to run ROOT and it works perfectly as far as I can see!

In my home dir I also have a .bashrc file, which is called by .profile.
By adding echo $ROOTSYS I can see that:

  • after .bashrc ROOTSYS is undefined;
  • after .profile ROOTSYS is set to home (as env says)

I tried to manually change ROOTSYS and PYTHONPATH by adding (at the end of .profile):

ROOTSYS=/mnt/d/root6.18:$ROOTSYS
PYTHONPATH=/mnt/d/root6.18/lib:$PYTHONPATH

Now, if I try to import ROOT in python I get the following:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/mnt/d/root6.18/lib/ROOT.py", line 24, in <module>
    import cppyy
  File "/mnt/d/root6.18/lib/cppyy.py", line 61, in <module>
    import libPyROOT as _backend
ImportError: libTree.so: cannot open shared object file: No such file or directory

Anyways, if I manually run thisroot I can still import ROOT without any problem.

Thank you!

I don’t know the WSL file structure, but it seems weird that ROOT works when your variables are pointing to “home” yet your ROOT seems to be in “/mnt/d”. If ROOT is working with that configuration I suppose it should also run in python. A few things:
1 - What is the output of:

cd; pwd; ls -a

and then:

cat .bashrc

and

cat .profile

2 - Do you really need to compile root? You can just use the precompiled version for ubuntu 18 (as long as you have a 64-bit system, and since you already compiled it you should already have all the prerequisites installed); delete all current references to root in your bashrc and profile files, unzip the download to a folder and add only the “source” line at the end of .bashrc); this should be all that you need in normal situations.

Alright, thanks to your advice I think I’ve spotted the problem: I’ll try to describe it because it could happen to anyone using WSL.
There is a conflict between WSL and Windows, since my ROOT dir is in a partition outside WSL’s environment. This means that, when thisroot.sh is executed by .profile, it can’t find root-config and it leads to this error:

root-config: command not found

When I first built ROOT I found a workaround by adding ROOT’s dir in Windows’ environmental variable (path): this variable is added in WSL $PATH and thisroot.sh could finally find root-config.
That’s why I could run ROOT even if WSL variables were pointing “home”; but I couldn’t use pyROOT because those variables wern’t set correctly.

I solved the problem by removing ROOT from Windows’ path and setting WSL’s environmental variables manually, by creating a script (sourced by .profile) containig the following lines:

export ROOTSYS=/mnt/d/root6.18
export PATH=$PATH:$ROOTSYS/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib
export PYTHONPATH=$PYTHONPATH:$ROOTSYS/lib
. /mnt/d/root6.18/bin/thisroot.sh

I’m clearly not an expert on these things, so I’m wondering if what I’ve said and done makes sense! Thank you! :slight_smile:

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