Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPython doesn't reload code when running in the QTConsole

Tags:

python

ipython

qt

I'm running ipython qtconsole. I want to execute a file that I edit separately inside an editor. When I make changes to the file in the editor and re-run it in IPython using:

%run myfile.py

the code isn't updated. However, if I run ipython normally from the terminal then this works fine. I tried to use autoreload in the QT console:

%load_ext autoreload
%autoreload

but it doesn't fix the problem. What is wrong here?

like image 715
lgd Avatar asked Nov 18 '15 23:11

lgd


People also ask

What is IPython Qtconsole?

This is a very lightweight widget that largely feels like a terminal, but provides a number of enhancements only possible in a GUI, such as inline figures, proper multiline editing with syntax highlighting, graphical calltips, and much more. The Qt console for IPython, using inline matplotlib plots.

What is Autoreload in IPython?

IPython extension to reload modules before executing user code. autoreload reloads modules automatically before entering the execution of code typed at the IPython prompt.


2 Answers

did you try:

import importlib
importlib.reload(<module_name>)
like image 148
Stéphane Avatar answered Sep 21 '22 06:09

Stéphane


You can use the general python reload instead of the ipython autoreload like:

reload(module)

Bear in mind that this will not automatically reload dependencies, so you would have reload any nested imports as well.

See this question as well

like image 36
Aryan Jain Avatar answered Sep 20 '22 06:09

Aryan Jain