我如何使用IPython作为我的Emacs Python解释器?

时间:2021-09-24 20:19:59

I'm running Emacs 22.1.1 and IPython 0.9.1 on OS X and I'd like to be able to run lines/methods/snippets of Python code from my current buffer on demand inside an IPython interpreter.

我在OS X上运行Emacs 22.1.1和IPython 0.9.1,我希望能够在IPython解释器中根据需要从当前缓冲区运行Python代码的行/方法/片段。

What do I need to do to get this working?

为了让这个工作,我需要做什么?

3 个解决方案

#1


4  

also ipython wont load with the official python.el being used with emacs 23.1.1

ipython也不会加载与emacs 23.1.1一起使用的官方python.el

#2


4  

This version of emacs for mac:

这个版本的emacs for mac:

http://emacsformacosx.com

comes with package.el pre-installed. This allows you to automatically install emacs packages. There is a package called ein:

随附package.el预装。这允许您自动安装emacs包。有一个名为ein的包:

http://tkf.github.io/emacs-ipython-notebook/

which makes it easy to interact with ipython from emacs (including notebooks).

这使得从emacs(包括笔记本)与ipython交互变得容易。

However, as of version 24.3 of the emacs above, ein is not in the default package repository. If you add more repositories, as per:

但是,从上面的emacs版本24.3开始,ein不在默认包存储库中。如果您添加更多存储库,则按照:

http://www.emacswiki.org/emacs/ELPA

i.e., add this to your ~/.emacs file:

即,将其添加到〜/ .emacs文件中:

(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
                     ("marmalade" . "http://marmalade-repo.org/packages/")
                     ("melpa" . "http://melpa.milkbox.net/packages/")))

then call

M-x package-refresh-contents

you will now be able to add ein with:

你现在可以添加ein:

M-x package-install <ret> ein

alas the MELPA version of ein does not work with ipython > 1.x so if you are using ipython 2.x, you need a newer build of ein:

唉,MELA版本的ein不适用于ipython> 1.x所以如果你使用的是ipython 2.x,你需要更新的ein版本:

https://github.com/tkf/emacs-ipython-notebook/issues/137

so clone that:

所以克隆:

git clone https://github.com/millejoh/emacs-ipython-notebook.git

copy the lisp sub directory somewhere sensible:

将lisp子目录复制到某个合理的位置:

cp -r emacs-ipython-notebook/lisp ~/.emacs.d/einv2

then add it to your emacs load path and load it, by adding this to your ~/.emacs:

然后将其添加到您的emacs加载路径并加载它,将其添加到〜/ .emacs:

(add-to-list 'load-path "~/.emacs.d/einv2")
  (require 'ein)

finally, get rid of the old ein, which will leave the dependencies in place:

最后,摆脱旧的ein,这将留下依赖关系:

M-x package-list-packages

scroll to ein in the package list, then:

滚动到包列表中的ein,然后:

M-x package-menu-mark-delete
M-x package-menu-execute

Restart emacs and you can connect to your ipython notebook server:

重新启动emacs,您可以连接到您的ipython笔记本服务器:

M-x ein:notebooklist-open

#3


0  

python-mode.el supports IPython natively.

python-mode.el原生支持IPython。

Just make sure shebang doesn't point to another interpreter.

只要确保shebang不指向另一个翻译。

In this case:

在这种情况下:

  • either call a command with ending "-ipython", which will override shebang
  • 要么调用一个结尾为“-ipython”的命令,它将覆盖shebang

  • customize "ipython" as default interpreter and set `py-force-py-shell-name-p'. This might be done also via menu Python/.../Switches
  • 自定义“ipython”作为默认解释器并设置`py-force-py-shell-name-p'。这也可以通过菜单Python /.../ Switches来完成

#1


4  

also ipython wont load with the official python.el being used with emacs 23.1.1

ipython也不会加载与emacs 23.1.1一起使用的官方python.el

#2


4  

This version of emacs for mac:

这个版本的emacs for mac:

http://emacsformacosx.com

comes with package.el pre-installed. This allows you to automatically install emacs packages. There is a package called ein:

随附package.el预装。这允许您自动安装emacs包。有一个名为ein的包:

http://tkf.github.io/emacs-ipython-notebook/

which makes it easy to interact with ipython from emacs (including notebooks).

这使得从emacs(包括笔记本)与ipython交互变得容易。

However, as of version 24.3 of the emacs above, ein is not in the default package repository. If you add more repositories, as per:

但是,从上面的emacs版本24.3开始,ein不在默认包存储库中。如果您添加更多存储库,则按照:

http://www.emacswiki.org/emacs/ELPA

i.e., add this to your ~/.emacs file:

即,将其添加到〜/ .emacs文件中:

(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
                     ("marmalade" . "http://marmalade-repo.org/packages/")
                     ("melpa" . "http://melpa.milkbox.net/packages/")))

then call

M-x package-refresh-contents

you will now be able to add ein with:

你现在可以添加ein:

M-x package-install <ret> ein

alas the MELPA version of ein does not work with ipython > 1.x so if you are using ipython 2.x, you need a newer build of ein:

唉,MELA版本的ein不适用于ipython> 1.x所以如果你使用的是ipython 2.x,你需要更新的ein版本:

https://github.com/tkf/emacs-ipython-notebook/issues/137

so clone that:

所以克隆:

git clone https://github.com/millejoh/emacs-ipython-notebook.git

copy the lisp sub directory somewhere sensible:

将lisp子目录复制到某个合理的位置:

cp -r emacs-ipython-notebook/lisp ~/.emacs.d/einv2

then add it to your emacs load path and load it, by adding this to your ~/.emacs:

然后将其添加到您的emacs加载路径并加载它,将其添加到〜/ .emacs:

(add-to-list 'load-path "~/.emacs.d/einv2")
  (require 'ein)

finally, get rid of the old ein, which will leave the dependencies in place:

最后,摆脱旧的ein,这将留下依赖关系:

M-x package-list-packages

scroll to ein in the package list, then:

滚动到包列表中的ein,然后:

M-x package-menu-mark-delete
M-x package-menu-execute

Restart emacs and you can connect to your ipython notebook server:

重新启动emacs,您可以连接到您的ipython笔记本服务器:

M-x ein:notebooklist-open

#3


0  

python-mode.el supports IPython natively.

python-mode.el原生支持IPython。

Just make sure shebang doesn't point to another interpreter.

只要确保shebang不指向另一个翻译。

In this case:

在这种情况下:

  • either call a command with ending "-ipython", which will override shebang
  • 要么调用一个结尾为“-ipython”的命令,它将覆盖shebang

  • customize "ipython" as default interpreter and set `py-force-py-shell-name-p'. This might be done also via menu Python/.../Switches
  • 自定义“ipython”作为默认解释器并设置`py-force-py-shell-name-p'。这也可以通过菜单Python /.../ Switches来完成