Skip to content Skip to sidebar Skip to footer

Ipython Not Reloading Modules

I'm running IPython in an emacs shell using: ;; Set IPython interpreter in my init.el (defvar python-shell-interpreter 'ipython') (defvar python-shell-interpreter-args '-i') Then:

Solution 1:

It turns out that IPython's %run command does not reload modules.

My current workaround is:

  1. Add the code below to ~/.ipython/profile_default/ipython_config.py
  2. Use $run myprog.py args

.

# this code in `~/.ipython/profile_default/ipython_config.py`# get_config() is injected into the global namespace whilst# config files are loadedc = get_config()

# Autoreload modulesc.InteractiveShellApp.extensions = ['autoreload']
c.InteractiveShellApp.exec_lines = ['%autoreload 2']

I didn't realise that %run does not reload modules because I'm used to using Spyder's runfile command, which does. It's nuts that %run doesn't and I'd like to submit a patch to fix it at some point.

On Windows, the HOME environment variable must be set so that the run-python command in emacs can read the IPython profile. If HOME is not set, you can add this to your init.el:

(add-hook 'inferior-python-mode-hook (lambda ()
                                       (progn
                                         (python-shell-send-string-no-output "%load_ext autoreload")
                                         (python-shell-send-string-no-output "%autoreload 2"))))

Post a Comment for "Ipython Not Reloading Modules"