How to contribute to Root Code?

Hi @Sayandeep_Ghosh,

Could you please check that the PATH and PYTHONPATH environment variables are updated accordingly after sourcing thisroot.sh, e.g. by typing

$ echo $PYTHONPATH
$ echo $PATH

?

Also, is your Python interpreter running within WSL?

Cheers,
J.

1 Like

Hi, after writing the command given by you I got a pretty large result e.g.

sayang@DESKTOP-IFS80HM:~$ echo $PYTHONPATH

sayang@DESKTOP-IFS80HM:~$ echo $PATH
/home/sayang/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Program Files/WindowsApps/CanonicalGroupLimited.Ubuntu20.04onWindows_2004.2021.825.0_x64__79rhkp1fndgsc:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files/Intel/WiFi/bin/:/mnt/c/Program Files/Common Files/Intel/WirelessCommon/:/mnt/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/mnt/c/Program Files/NVIDIA Corporation/NVIDIA NvDLISR:/mnt/c/Program Files/Java/jdk-11.0.4/bin:/mnt/c/Program Files (x86)/HP/Common/HPDestPlgIn/:/mnt/c/Program Files (x86)/Brackets/command:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Sayan_D/New folder/runtime/win64:/mnt/c/Sayan_D/New folder/bin:/mnt/c/Sayan_D/New folder/polyspace/bin:/mnt/c/Program Files (x86)/PuTTY/:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files/Microsoft SQL Server/140/Tools/Binn/:/mnt/c/Program Files/Microsoft SQL Server/Client SDK/ODBC/170/Tools/Binn/:/mnt/c/Program Files/dotnet/:/mnt/c/Program Files/Microsoft SQL Server/130/Tools/Binn/:/mnt/c/MinGW/bin:/mnt/c/Users/91704/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/91704/.dotnet/tools:/mnt/c/Users/91704/AppData/Local/Programs/Microsoft VS Code/bin:/snap/bin

And yes, my python interpreter is running within WSL

sayang@DESKTOP-IFS80HM:~$ which python3
/usr/bin/python3

Still I am getting import error.
Thanks !

Hi,
you still have an empty PYTHONPATH (see my comment above), so maybe you are not calling source /path/to/your/root/installation/bin/thisroot.sh ?

Cheers,
Enrico

1 Like

Hi,
Does that mean I should do this…
sayang@DESKTOP-IFS80HM:~$ export PYTHONPATH=/home/sayang/root-6.24.04/bin/thisroot.sh

But import error is still coming …
Thanks!

No, you really need to call source /home/sayang/root-6.24.04/bin/thisroot.sh as per point 4 of the instructions at /home/sayang/root-6.24.04 . That command sets all required environment variables for that shell session.

For the meaning of PYTHONPATH and what generally goes in there, see e.g. python - What exactly should be set in PYTHONPATH? - Stack Overflow

1 Like

I have read the link given by you and also followed a question related to pythonpath in the newbie section

In the above question it has been told to export pythonpath in this way to avoid import error:
export PYTHONPATH=$(root-config --libdir)

But even after doing this my import error is still coming and I have also called
source /home/sayang/root-6.24.04/bin/thisroot.sh after exporting pythonpath based on the answer given in the above question. Thanks!

Hi @Sayandeep_Ghosh,

You have to make sure that ROOT was built with PyROOT support, i.e. check in the output of root-config --features. If you cannot find pyroot in the output, you should build ROOT specifying:

$ cmake -Dpyroot=ON ...

After enabling pyroot, as @eguiraud said, thisroot.sh should take care of setting $PYTHONPATH. Let us know if that’s not the case.

Cheers,
J.

1 Like

Hi @jalopezg ,
Thanks a lot for your help. I just realized a huge mistake that I have made…

sayang@DESKTOP-IFS80HM:~$ root-config --features
cxx14 asimage builtin_afterimage builtin_clang builtin_cling builtin_llvm builtin_lz4 builtin_lzma builtin_nlohmannjson builtin_openui5 builtin_pcre builtin_tbb builtin_vdt builtin_xrootd builtin_xxhash builtin_zstd clad dataframe exceptions gdml http imt mlp roofit webgui root7 runtime_cxxmodules shared ssl tmva spectrum vdt x11 xrootd

sayang@DESKTOP-IFS80HM:~$ root-config --has-python
no
Although I have installed Python but still my python binding is missing in root-config --features. After seeing another one facing issue like me in this following link

I realized that I need to rebuild root from scratch. Does that mean I should reinstall ROOT or there is any other way.
Actually I followed this video to install root through WSL
Installing CERN ROOT in Windows with WSL - YouTube
Thanks!

Hi @Sayandeep_Ghosh,

Yes, if you installed ROOT building from sources, you need to rebuild (+ install) including PyROOT. To do so, be sure to include -Dpyroot=ON in the cmake command line, e.g.

$ cmake -Dpyroot=ON ...

Reusing the same build directory should (hopefully) work for an incremental build, which saves some compilation time.

Cheers,
J.

1 Like

Yes, if you installed ROOT building from sources, you need to rebuild (+ install) including PyROOT. To do so, be sure to include -Dpyroot=ON in the cmake command line, e.g.

No , I haven’t build from the sources from github. Is there any way to include python bindings or pyroot root-config --features by providing any one or two line command in wsl ubuntu terminal?
I actually followed this video to install root which doesn’t include installing pyroot and python

Please help! I have been stuck here for months…

Hi @Sayandeep_Ghosh,

What is shown in the video is how to build and install ROOT from sources. Typically, this is for advanced users only (or for some specific cases). The recommended way of installing ROOT is either through package managers or Conda, as seen in the Installation guide.

That said, now that you already built succesfully ROOT from sources, I would recommend to perform the following steps from the buildroot/ directory:

$ cmake -Dpyroot=ON ../
$ make -j4
$ make install

Cheers,
J.

1 Like

Hi @jalopezg ,
I have followed the steps successfully as told by you. Still after writing root-config --features it is not showing Python or PyRoot. Is there any one or two line command to include python in root-config --features?

ImportError: Failed to import libcppyy2_7. Please check that ROOT has been built for Python 2.7

All the .C files are running successfully but whenever I try to compile .py files for e.g rf204_extrangefit.py it is showing the import error but now its not showing “No module names ROOT”. Thanks for your help again! its started to work properly but still not able to run .py files in tutorials/roofit.

sudo apt-get install python3-dev python2-dev

1 Like

Thanks, pyroot is now present in root -config–features but not python. Also I would like to know whether I can solve this error after including Python 2.7 in root -config–features

ImportError: Failed to import libcppyy2_7. Please check that ROOT has been built for Python 2.7

Thanks!

1 Like

Hi @Wile_E_Coyote ,
I am using the same python version as it is in my root binaries which were built and pyroot is also present.(3.8.10 in ROOT 6).
In spite of all this I got this error when running

sayang@DESKTOP-IFS80HM:~/root-6.24.04/tutorials/roofit$ python rf204_extrangefit.py

ImportError: Failed to import libcppyy2_7. Please check that ROOT has been built for Python 2.7

Post the output of commands shown in the two links in my previous post.

1 Like

sayang@DESKTOP-IFS80HM:~/root-6.24.04/tutorials/roofit$ root-config --has-pyroot
yes

sayang@DESKTOP-IFS80HM:~/root-6.24.04/tutorials/roofit$ root-config --python3-version
3.8.10

So, use “python3”.

1 Like

Hi @Wile_E_Coyote!
Thanks a lot for your help, I have been stuck here for months. If you can also share some advice on how to get started with root for beginners it will be grateful. Thanks!