pyROOT in virtualenv

Viewed 560

I want to use pyROOT in a virtualenv, I have ROOT installed on my system, when outside the virtualenv I can do import ROOT and it works, but inside a virtualenv doing an import ROOT gives the following error:

ModuleNotFoundError: No module named 'ROOT'

How do I add ROOT in there?

Thanks in advance.

3 Answers

You'll need to install root within the virtual environment too. Run a pip install command after activating the environment.

Like many Python packages, support for the ROOT framework in Python exists as two parts...a C++ framework, and a Python binding around that framework. In this case, both the C++ framework and the Python binding are provided by the same group and so are discussed together on the same web site. https://root.cern is the home page for the framework, and https://root.cern/manual/python is the Python module page.

The C++ framework should be installed first. How that is done will vary by platform. Then, the Python module should be installed into each Python version and/or virtual environment in which one wishes to use the ROOT framework, via the command:

pip install pyroot

Say you have a virtualenv in the directory ~/envs/myenv. You'd then want to do:

source ~/envs/myenv/bin/activate
pip install pyroot

Install pyroot. try "pyroot file.py" instead of "python file.py"

Related