JupyterLab - problems importing module 'numexpr'

Hi,

The following code works fine in ‘ipython’ but I cannot get it to work in JupyterLab:

import math
loops = 2500000
a = range(1, loops)
import numexpr as ne
ne.set_num_threads(1)
f = '3 * log(a) + cos(a) ** 2'
%timeit r = ne.evaluate(f)

I get this error:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[6], line 1
----> 1 import numexpr as ne
      2 ne.set_num_threads(1)
      3 f = '3 * log(a) + cos(a) ** 2'

ModuleNotFoundError: No module named 'numexpr'

I think maybe JupyerLab is using a different environment or something. Can someone tell me how to make this work?

FYI, this code is from “Python for Finance” 2e.

Ok I fixed this by doing pip install numexpr in a Jupyter cell and running that cell. What fun.

Note this depends on how you installed jupyterlab in the first place. (Just so that others with a similar problem check that first.)

1 Like

I installed the “JupyterLab Desktop” flatpak from the “Discover” GUI.

There you have it :slight_smile:
It’s good you found a solution, and even better you shared it here. That’s the Fedora way!

jupyterlab can be installed via rpm, via pip, pipx or (as I learned here) flatpak. All (most) of them use different python installations and/or python module paths (virtual environments). That explains why your system (i)python saw the module which your flatpak jupyterlab’s python “kernel” couldn’t see.