Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ipython notebook is not updating when I change my code

So, I ran into a weird issue using an ipython notebook and not sure what to do. Normally, when I run a part of the code, if there is an error, I would trace it back, fix it, and then re-run the code. I was doing a similar thing but even after making changes to the code, it looks like nothing is changing!

Here is the example... I am using Python 3.5 so xrange is gone. This then caused an error to be thrown:

XXXX      24     XXXX      25     XXXX ---> 26     for t in xrange(0,len(data),1):      27       28         XXXX       NameError: name 'xrange' is not defined 

but after changing my code (which you can see below the difference in line 26), the same error pops up!

XXXX      24     XXXX      25     XXXX ---> 26     for t in range(0,len(data),1):      27       28     XXX       NameError: name 'xrange' is not defined 

Any ideas on why this would be happening?

like image 882
Max Henderson Avatar asked Jan 13 '16 03:01

Max Henderson


People also ask

How do I change the code on a Jupyter Notebook?

Edit mode. When a cell is in edit mode, you can type into the cell, like a normal text editor. Enter edit mode by pressing Enter or using the mouse to click on a cell's editor area.

How do you reload a Jupyter Notebook?

Simple solution: Use the autoreload to make sure the latest version of the module is used. The autoreloading module is not enabled by default. So you have to load it as an extension. And each time you execute some code, IPython will reimport all the modules to make sure that you are using the latest possible versions.

How do I reset my IPython notebook?

You can restart your Jupyter Kernel by simply clicking Kernel > Restart from the Jupyter menu. Note: This will reset your notebook and remove all variables or methods you've defined! Sometimes you'll notice that your notebook is still hanging after you've restart the kernel. If this occurs try refreshing your browser.

Why the code is not running in Jupyter Notebook?

Jupyter doesn't load or doesn't work in the browserTry disabling any browser extensions and/or any Jupyter extensions you have installed. Some internet security software can interfere with Jupyter. If you have security software, try turning it off temporarily, and look in the settings for a more long-term solution.


2 Answers

As Thomas K said, you're probably making a change in an external file that was not imported. There is a very useful command in ipython notebook for such cases, called autoreaload. With autoreaload, whenever you modify an external file you do not have to import it again because the extension takes care of it for you. For more information check: ipython autoreload.

like image 68
Christian Gomes Avatar answered Sep 18 '22 17:09

Christian Gomes


Whenever using external files along with Ipython use autoreload. It will reload the external files every time before executing any code in IPython.

Add this at first cell of the IPython.

%load_ext autoreload %autoreload 2 
like image 43
R Kumar Avatar answered Sep 21 '22 17:09

R Kumar