Python ROOT inside of Virtual Environment

I installed root using the Pacman package manager and pyroot seems to work fine in python when no virtual envorinment is activated:

➜  root git:(master) ✗ python3
Python 3.11.8 (main, Feb 12 2024, 14:50:05) [GCC 13.2.1 20230801] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>>

However if I activate a virtial environment, python is not able to find it:

➜  root git:(master) ✗ source .venv/bin/activate
(.venv) ➜  root git:(master) ✗ which python3
/popos/home/caspar/Documents-old/code/root/.venv/bin/python3
(.venv) ➜  root git:(master) ✗ python3
Python 3.11.8 (main, Feb 12 2024, 14:50:05) [GCC 13.2.1 20230801] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'ROOT'
>>>

Does anyone know how to resolve this? I saw that using thisroot.sh seems to be discontinued.


ROOT Version: 6.30.02-2
Platform: Arch Linux x86_64 6.7.9-arch1-1
Compiler: Python 3.11.8-1


Hi,

Thanks for the interesting post and welcome to the ROOT community!

Why do you say thisroot.sh seems to be discontinued? In the mean time, I add in the loop @vpadulan and @jonas .

Best,
D

Hi @TheFibonacciEffect,

welcome to the ROOT forum!

It’s true that the Arch Linux ROOT package is set up in such a way that thisroot.sh is not needed anymore.

Concerning your problem: ROOT is installed in the system packages, and when you create a Python virtual environment all packages outside the virtual environment are ignored. This has nothing to do with ROOT, try the same with numpy :slight_smile:

The solution is to create your virtual environment with the --system-site-packages flag to specify that you want to also use system packages.

See also this discussion on stackoverflow: