如何使用Emacs运行Python代码? [英] How do you run Python code using Emacs?

查看:385
本文介绍了如何使用Emacs运行Python代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行Python代码以使用Emacs进行测试和调试。我应该如何在* .py文件中调试和运行代码?我尝试使用 M-x编译命令。使用 Mx编译,我得到了一个崩溃的编译缓冲区(它说Python正在编译,但是什么也没发生)。

I'm trying to run Python code for testing and debugging using Emacs. How should I debug and run code in *.py files ? I tried using the M-x compile commands . Using M-x compile, I get a compilation buffer that crashes (It says Python is compiling, but then nothing happens).

推荐答案

如果您使用的是emacs24,则应为默认设置(在emacs23中,您需要使用python.el,而不是python-mode.el):

If you are using emacs24 this should be the default (in emacs23 you need python.el, not python-mode.el):

在python缓冲区中:

In a python buffer:


  • Cc Cz:打开python shell

  • Cc Cc:在打开的python shell中运行缓冲区的内容

  • Cc Cr:在python shell中运行所选区域

默认的python shell是 python,如果您需要使用ipython,则可以在.emacs中使用此conf

default python shell is "python", if you nee to use ipython you can use this conf in your .emacs

(setq
 python-shell-interpreter "ipython"
 python-shell-interpreter-args "--colors=Linux --profile=default"
 python-shell-prompt-regexp "In \\[[0-9]+\\]: "
 python-shell-prompt-output-regexp "Out\\[[0-9]+\\]: "
 python-shell-completion-setup-code
 "from IPython.core.completerlib import module_completion"
 python-shell-completion-module-string-code
 "';'.join(module_completion('''%s'''))\n"
 python-shell-completion-string-code
 "';'.join(get_ipython().Completer.all_completions('''%s'''))\n")

当然,前提是您的系统中安装了ipython:)

provided that you have ipython installed in your system of course :)

ipython > = 5具有自动完成功能,可以破坏emacs子外壳,您可以通过更改以下行来解决此问题

python-shell-interpreter-args --colors = Linux --profile = default

并添加-简单提示

ipython>=5 has a auto-complete feature which breaks the emacs sub-shell, you can fix this by changing this line python-shell-interpreter-args "--colors=Linux --profile=default" and add --simple-prompt.

它将允许您正确地查看ipython,但是由于某些原因,我仍然无法获得emacs中的自动完成功能。

It will allow you to see ipython correctly but for some reason I did not get yet the auto-completion in emacs is not as effective as it used to be.

这篇关于如何使用Emacs运行Python代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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