While Using %%time for the first time, I had entered that magic into a cell which
contained a comment, resulting in this error message.
%%time
time.sleep(.5)
"UsageError: Line magic function %%time not found."
<--- Blank line before %%time also causes the problem
%%time
time.sleep(.5)
"UsageError: Line magic function %%time not found."
Removing the comment made the error go away.
%%time
time.sleep(.5)
Wall time: 500 ms
Is it normal that the CPU time is not displayed on Windows?
My system is running Windows 7 Pro, 64-Bit
jupyter 1.0.0 py_1 conda-forge
jupyter_client 5.2.4 py_1 conda-forge
jupyter_console 6.0.0 py_0 conda-forge
jupyter_core 4.4.0 py_0 conda-forge
(py36sci) C:>conda list conda
msys2-conda-epoch 20160418 1
(py36sci) C:>conda list python
ipython 7.2.0 py36h39e3cac_1000 conda-forge
ipython_genutils 0.2.0 py_1 conda-forge
python 3.6.6 he025d50_0 conda-forge
python-dateutil 2.7.5 py_0 conda-forge
I think cell magics %% should start from the first line by convention. That's why they are called cell magics. For example, the line magic would work just fine and probably is preferred for usage
%time time.sleep(5)
If that's the case, it needs to be documented. However, a leading comment IS valid Python code, so it has to work for valid Python. Will wait until the developers comment
Encountering this same issue
UsageError: Line magic function %%timeit not found.
Code:
%%timeit -n 100
summary = np.sum(sprice)
@bencarpena Whenever using magic functions, you must keep it as the first line in your code. Try it this way and it should work:
%%timeit -n 100
#2 - Parallel computing feature (functional programming)
summary = np.sum(sprice)
I think this issue can be closed.
As an fyi for anyone, I have a real world example where i'm using nbdev and have a cell like:
# hide
%%timeit -r2 -n5
df = do_stuff(df)
print(df.shape)
the "# hide" here is telling nbdev to not include the cell in my docs. I am just using the %%timeit under my function definition to make sure changes I make don't slow it down significantly.
Not sure what a good solution would be and probably more up to nbdev to handle itself maybe (ignore cell magics when looking for "# hide").
But just wanted to share my example here in case interesting or relevant to anyone else coming along and reading this.
Most helpful comment
I think cell magics %% should start from the first line by convention. That's why they are called cell magics. For example, the line magic would work just fine and probably is preferred for usage