ipython没有重装模块 [英] ipython not reloading modules

查看:219
本文介绍了ipython没有重装模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在emacs shell中使用以下命令运行IPython:

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")

然后:


  1. 用<$ c启动IPython $ c> Mx run-python

  2. 使用%run myprog.py 在IPython中运行程序。 myprog.py导入一个名为 mymodule 的模块。

  1. Start IPython with M-x run-python
  2. Run a program within IPython with %run myprog.py. myprog.py imports a module called mymodule.

我对<进行更改 mymodule 但当我再次运行%run myprog.py 时,它会运行原来的 mymodule ,而不是更改的代码。

I make changes to mymodule but when I run %run myprog.py again, it runs the original mymodule, not the changed code.

FWIW,我正在使用emacs 24.5前奏,在Windows 10上使用Anaconda和Python 3.5。

FWIW, I'm using emacs 24.5 prelude, on Windows 10 with Anaconda and Python 3.5.

推荐答案

事实证明 IPython的%run 命令不会重新加载模块

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

我目前的解决方法是:


  1. 将以下代码添加到〜/ .ipython / profile_default / ipython_config.py

  2. 使用 $ run myprog.py args

  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 loaded
c = get_config()

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

我没有意识到%run 没有重新加载模块,因为我习惯使用Spyder的 runfile 命令,确实如此。很遗憾%run 没有,我想在某个时候提交补丁来修复它。

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.

在Windows上,必须设置HOME环境变量,以便在<$ c $中使用 run-python 命令c> emacs 可以读取IPython配置文件。如果未设置HOME,您可以将其添加到 init.el

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"))))

这篇关于ipython没有重装模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆