3

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.

Keldorn
  • 1,980
  • 15
  • 25
A Deshmukh
  • 43
  • 8

4 Answers4

2

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

CryptoFool
  • 21,719
  • 5
  • 26
  • 44
D Hudson
  • 1,004
  • 5
  • 12
  • root isn't a python package, it is the c++ framework, you just install it using your system package manager, and can somehow directly use it in python (outside virtualenv atleast) – A Deshmukh Mar 02 '21 at 12:21
  • @ADeshmukh, I believe that `ROOT` is a C++ framewok, and `pyROOT` is a Python module that wraps a Python API around it. So this answer does make sense...the OP should try `pip install pyroot` while inside the virtual environment. – CryptoFool Mar 07 '21 at 06:30
0

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
CryptoFool
  • 21,719
  • 5
  • 26
  • 44
0

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

0

You need to add ROOT to your python path. You can do this by creating an environment variable PYTHONPATH with the value of your bin folder in the root install directory.

This is how it looks for me on windows: enter image description here

To verify it had worked, you can

import sys
print(sys.path)

And check if the bin directory is in there.

dor00012
  • 362
  • 4
  • 17