Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

emacs and python updating modules

atm i'm using emacs to write some python code, so far it works quite fine except one problem that is really a bit annoying.

Always when I update something inside a self written module i reevaluate the buffer and the module in the python shell inside emacs doesn't get updated. i always have to end the python process and start it again to get the change. I figured out that emacs copies some things to a tmp dir to execute them, so i guess it has something to do with this.

Maybe someone out there had the same problem and solved it already so help would be appreciated

like image 265
Xtroce Avatar asked Sep 15 '25 20:09

Xtroce


2 Answers

You have to reload the module manually in the shell in order for it to take effect.

See the documentation here on the Python reload function

I asked a similar question which you can see here

like image 125
justinhj Avatar answered Sep 17 '25 11:09

justinhj


I found a better solution that needs no emacs config:

simply do

$ ipython profile create

that should create ipython profile in

$HOME/.ipython/profile_default/ipython_config.py  

then put the following inside

c = get_config()
c.TerminalInteractiveShell.editor = 'emacsclient'
c.InteractiveShellApp.extensions = [
     'autoreload'
]

c.InteractiveShellApp.exec_lines = []
c.InteractiveShellApp.exec_lines.append('%load_ext autoreload')
c.InteractiveShellApp.exec_lines.append('%autoreload 2')

then restart emacs. Now each time you save changes to file inside emacs - ipython would reload it automatically

and the following I have in my emacs config

;; ------------------
;; misc python config
;; ------------------
(company-mode -1)
(elpy-enable)
(elpy-use-ipython "ipython")
(setq python-shell-interpreter "ipython" python-shell-interpreter-args "--simple-prompt --pprint")
(setq python-check-command "flake8")
(setq elpy-rpc-backend "jedi")
(setq elpy-rpc-python-command "python")
; https://github.com/gregsexton/ob-ipython/issues/28
(setq python-shell-completion-native-enable nil)

if you want to see my full python config, it's here

like image 37
DmitrySemenov Avatar answered Sep 17 '25 10:09

DmitrySemenov