OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How does autoreload work with jupyter?

  • Thread starter Thread starter ceiling cat
  • Start date Start date
C

ceiling cat

Guest
I have a file mytest.py in the working directory, with the following content:

Code:
class MyTest(object):

  def __init__(self):
    print(1)
    pass

In jupyter I have these cells.

Cell 1:

Code:
%reload_ext autoreload
%autoreload 2
import mytest

Cell 2:

Code:
x = mytest.MyTest()

If I start with a fresh kernel then it works as expected, and it gives me 1. Now if I go into mytest.py and change the print out to 2 and rerun Cell 2 I would get:

Code:
1
[autoreload of mytest failed: Traceback (most recent call last):
  File "/Users/myusername/anaconda/lib/python3.5/site-packages/IPython/extensions/autoreload.py", line 247, in check
    superreload(m, reload, self.old_objects)
NameError: name 'reload' is not defined
]
[autoreload of mytest failed: Traceback (most recent call last):
  File "/Users/myusername/anaconda/lib/python3.5/site-packages/IPython/extensions/autoreload.py", line 247, in check
    superreload(m, reload, self.old_objects)
NameError: name 'reload' is not defined
]

If I run Cell 2 again now I'd get just 1 without any errors, but it still has not used the new code.

I can't figure out how to reload the module properly without restarting the kernel, which I can't do because I have some very time-consuming code in the real program.

I have tried this in IPython in terminal. Although instantiating the class after modifying the code also gives me errors (note that it's a different error: AttributeError: 'NoneType' object has no attribute '__dict__') but it would use the updated code if I run it again. So it seems to me that this is a problem specific to jupyter.

What should I do to fix this?

EDIT (adding version info): Anaconda 2.5.0 Python 3.5.0 IPython 4.1.2 jupyter 4.1.0 Mac OS X 10.11.2
<p>I have a file <code>mytest.py</code> in the working directory, with the following content:</p>

<pre><code>class MyTest(object):

def __init__(self):
print(1)
pass
</code></pre>

<p>In <code>jupyter</code> I have these cells.</p>

<p>Cell 1:</p>

<pre><code>%reload_ext autoreload
%autoreload 2
import mytest
</code></pre>

<p>Cell 2:</p>

<pre><code>x = mytest.MyTest()
</code></pre>

<p>If I start with a fresh kernel then it works as expected, and it gives me <code>1</code>. Now if I go into <code>mytest.py</code> and change the print out to 2 and rerun Cell 2 I would get:</p>

<pre><code>1
[autoreload of mytest failed: Traceback (most recent call last):
File "/Users/myusername/anaconda/lib/python3.5/site-packages/IPython/extensions/autoreload.py", line 247, in check
superreload(m, reload, self.old_objects)
NameError: name 'reload' is not defined
]
[autoreload of mytest failed: Traceback (most recent call last):
File "/Users/myusername/anaconda/lib/python3.5/site-packages/IPython/extensions/autoreload.py", line 247, in check
superreload(m, reload, self.old_objects)
NameError: name 'reload' is not defined
]
</code></pre>

<p>If I run Cell 2 again now I'd get just <code>1</code> without any errors, but it still has not used the new code.</p>

<p>I can't figure out how to reload the module properly without restarting the kernel, which I can't do because I have some very time-consuming code in the real program.</p>

<p>I have tried this in <code>IPython</code> in terminal. Although instantiating the class after modifying the code also gives me errors (note that it's a different error: <code>AttributeError: 'NoneType' object has no attribute '__dict__'</code>) but it would use the updated code if I run it again. So it seems to me that this is a problem specific to <code>jupyter</code>.</p>

<p>What should I do to fix this?</p>

<p>EDIT (adding version info):
Anaconda 2.5.0
Python 3.5.0
IPython 4.1.2
jupyter 4.1.0
Mac OS X 10.11.2</p>
 

Latest posts

Online statistics

Members online
0
Guests online
5
Total visitors
5
Top