1

I have troubles importing uproot in jupyter notebooks since some time ago. It worked fine before and it still works fine when importing it in my other python scripts, but when I try to import it in jupyter notebook it says ModuleNotFoundError: No module named 'uproot'. I am using virtual environment and the problem is strange because the uproot is surely installed in venv. Even if I try

!pip install uproot
import uproot

in one cell of the notebook, the output says:

Requirement already satisfied: uproot in ./.venv/lib/python3.6/site-packages (3.11.2)
Requirement already satisfied: awkward<1.0,>=0.12.0 in ./.venv/lib/python3.6/site-packages (from uproot) (0.12.20)
Requirement already satisfied: numpy>=1.13.1 in ./.venv/lib/python3.6/site-packages (from uproot) (1.18.1)
Requirement already satisfied: uproot-methods>=0.7.0 in ./.venv/lib/python3.6/site-packages (from uproot) (0.7.3)
Requirement already satisfied: cachetools in ./.venv/lib/python3.6/site-packages (from uproot) (4.0.0)
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-3-84117e7aebc9> in <module>
      1 get_ipython().system('pip install uproot')
----> 2 import uproot

/usr/lib/root/6.18/lib/ROOT.py in _importhook(name, *args, **kwds)
    531       except Exception:
    532          pass
--> 533    return _orig_ihook( name, *args, **kwds )
    534 
    535 __builtin__.__import__ = _importhook

ModuleNotFoundError: No module named 'uproot'

[EDIT] What I did now was to install jupyter-lab to venv and the problem seems to be deeper:

[In] !python3 -c "import uproot; print(uproot.__version__)"
[In] !which python3
[In] import uproot
[Out] 3.11.2
[Out] ...PATH.../.venv/bin/python3
----------------------------------------------
ModuleNotFoundErrorTraceback (most recent call last)
<ipython-input-9-f1317e967425> in <module>
      2 get_ipython().system('which python3')
      3 
----> 4 import uproot

ModuleNotFoundError: No module named 'uproot'
gasar8
  • 306
  • 4
  • 12
  • 1
    This looks like a problem with launching Jupyter from a different virtual environment than the one uproot is in. Jupyter is just another Python package, but when it runs Python, it has to do that from its own environment. Anyway, this is not an uproot issue, but a Jupyter+virtualenv one. – Jim Pivarski Feb 06 '20 at 14:43
  • Thank you for the answer, the problem is really because of the different environments, because I installed venv with --system-site-packages and it takes jupyter from the machine not from venv. Any idea how to install it also in venv (with `pip install` I only get `Requirement already satisfied`)? – gasar8 Feb 07 '20 at 10:08
  • (Not an answer; that's why it's in the comments section.) Maybe add `--no-cache` to pip? One problem I've found with pip is its overactive caching. Another throw-away suggestion: maybe use conda? It has virtual environments built-in, and it more fully takes over your Python environment, which you would need to get Jupyter to use the right Python. – Jim Pivarski Feb 07 '20 at 15:24

0 Answers0