Alexis Pister
Alexis Pister

Reputation: 499

Jupyter magic command %%time buggy in conda virtual environment

I use jupyter notebook with a python 3.6 installation. I created an anaconda virtual environment, and when I launch a jupyter notebook inside it, the %%time command seems buggy.

If I write a cell with the %%time command like follow :

%%time
a = 2

All my variables declarations are unknown in my following cells

print(a)

I get the following error :

NameError                Traceback (most recent call last)
<ipython-input-3-3f786850e387> in <module>
----> 1 a

NameError: name 'a' is not defined

However, it works just fine in my root environment. Please help.

Upvotes: 0

Views: 217

Answers (1)

rosebud
rosebud

Reputation: 69

The behaviour was changed in iPython 7.3 to work in this way:

https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-time

So I assume that your root environment must have an older version of iPython / Jupyter notebook.

Alternative option:

import time
start = time.time()

"the code you want to test stays here"

end = time.time()
print(end - start)

Upvotes: 1

Related Questions