wiking5
(Wiking)
February 26, 2025, 8:45pm
1
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.
wiking5
(Wiking)
February 26, 2025, 8:50pm
2
Ok I fixed this by doing pip install numexpr
in a Jupyter cell and running that cell. What fun.
mjg
(Michael J Gruber)
February 27, 2025, 9:13pm
3
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
wiking5
(Wiking)
February 28, 2025, 12:14am
4
I installed the “JupyterLab Desktop” flatpak from the “Discover” GUI.
mjg
(Michael J Gruber)
February 28, 2025, 8:27am
5
There you have it
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.