0

I am using spacemacs, anaconda-mode.

In file main.py, I imported a class from file a.py. Then I pressed C-c C-p to launch an ipython shell, and run main.py, everything is OK. But then I modified the class in a.py, and save, and rerun main.py, I found that the class in a.py was the previous version, which means ipython did not update the content in a.py! Only when I killed the python buffer, and relaunched the ipython shell, did the content in a.py be updated.

I tested this in Spyder, which is a python IDE, and it worked perfect as I expected. But what's wrong with emacs? Are there some configurations that I missed?

1

I have solved this problem.

First method: In ipython console, type

%load_ext autoreaload
%autoreload 2

Second method: Create configuration "dev" (or whatever):

ipython profile create dev
[ProfileCreate] Generating default config file: u'/home/username/.config/ipython/profile_dev/ipython_config.py'

And add these lines to "ipython_config.py":

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

Then set variables in Emacs config for python-mode:

(setq
   python-shell-interpreter "ipython"
   python-shell-interpreter-args "--profile=dev"
)

IPython started with this config will reload modules when you resend code to it.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.