使用emacs时的凌乱代码ipython Inferior Python

时间:2016-12-30 07:34:15

标签: python emacs ipython emacs25

我正在使用最新的emacs25.1.1和最新的archlinux。

但是,当我编辑python脚本并使用Ctrl-Enter将其发送到Inferior ipython时,劣质Python会向我显示一个丑陋的代码类似指示符,如:

Python 3.5.2 (default, Nov  7 2016, 11:31:36) 
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

[JIn [1]: import numpy as np[26D
[J
[6n[JIn [2]: [8D[8C[8D[J[6n[JIn [2]: [8D[8C

在此Inferior python中按Enter键时,显示:

error in process filter: Args out of range: "
^[[6n^[[0m^[[0m^[[J^[[0;38;5;28mIn [^[[0;38;5;28m: ^[[8D^[[8C[[0m^[[0m", 128

我从以下位置更改emacs区域设置:

LANG=zh_CN.UTF-8
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC=en_US.UTF-8
LC_TIME=en_US.UTF-8
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY=en_US.UTF-8
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER=en_US.UTF-8
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=

要:

LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=en_US.UTF-8
LC_TIME=en_US.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=en_US.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=en_US.UTF-8
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT=en_US.UTF-8
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

使用命令$" export LANGUAGE =" en_US:en" &安培;&安培; emacs" $,无助于解决凌乱的代码。

我也在emacs中尝试python-mode.et或elpy包,都显示相同 凌乱的终端代码。

此外,python2.7也尝试过,没有工作:

Python 2.7.12 (default, Nov  7 2016, 11:55:55) 
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

[JIn [1]: import numpy as np[26D
[J
[6n[JIn [2]: [8D[8C[8D[J[6n[JIn [2]: [8D[8C

最新的ipython问题?

最后,emacs中的消息粘贴在这里:

error in process filter: ansi-color-filter-apply: Args out of range: "Python 3.5.2 (default, Nov  7 2016, 11:31:36) 
Type \"copyright\", \"credits\" or \"license\" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

[6n[0m
[0m[J
[0m", 408
error in process filter: Args out of range: "Python 3.5.2 (default, Nov  7 2016, 11:31:36) 
Type \"copyright\", \"credits\" or \"license\" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

[6n[0m
[0m[J
[0m", 408
error in process filter: ansi-color-filter-apply: Args out of range: "[0m[0m[J[0;38;5;28mIn [[0;38;5;10;1m1[0;38;5;28m]: [0;38;5;28;1mimport[0m [0;38;5;32;1mnumpy[0m [0;38;5;28;1mas[0m [0;38;5;32;1mnp[26D[0m
[J[0m", 177
error in process filter: Args out of range: "[0m[0m[J[0;38;5;28mIn [[0;38;5;10;1m1[0;38;5;28m]: [0;38;5;28;1mimport[0m [0;38;5;32;1mnumpy[0m [0;38;5;28;1mas[0m [0;38;5;32;1mnp[26D[0m
[J[0m", 177
error in process sentinel: elpy-rpc--default-error-callback: peculiar error: "exited abnormally with code 1"
error in process sentinel: peculiar error: "exited abnormally with code 1"
error in process filter: ansi-color-filter-apply: Args out of range: #("[JIn [1]: import numpy as np[26D
[J


[6n[0m[0m[J[0;38;5;28mIn [[0;38;5;10;1m2[0;38;5;28m]: [8D[8C[0m[0m[8D[J[0m[6n[0m[0m[J[0;38;5;28mIn [[0;38;5;10;1m2[0;38;5;28m]: [8D[8C[0m" 0 38 (fontified nil) 38 39 (fontified nil)), 283
error in process filter: Args out of range: #("[JIn [1]: import numpy as np[26D
[J


[6n[0m[0m[J[0;38;5;28mIn [[0;38;5;10;1m2[0;38;5;28m]: [8D[8C[0m[0m[8D[J[0m[6n[0m[0m[J[0;38;5;28mIn [[0;38;5;10;1m2[0;38;5;28m]: [8D[8C[0m" 0 38 (fontified nil) 38 39 (fontified nil)), 283

2 个答案:

答案 0 :(得分:4)

我使用了https://github.com/jorgenschaefer/elpy/issues/992#issuecomment-249165923的推荐。简而言之 - 添加以下代码: (setenv "IPY_TEST_SIMPLE_PROMPT" "1")进入emacs配置文件。

答案 1 :(得分:0)

从输出和错误消息中,看起来由于某种原因,您的设置不处理ipython使用的ansi转义序列。假设您使用的是pythong-mode,请确保您拥有以下内容

(setq python-shell-interpreter "ipython"
      python-shell-interpreter-args "-i")

要消除init文件中的其他可能设置,我会注释掉除上述内容之外的所有内容,然后重试。如果它工作,那么你的设置中有一些东西正在弄乱emacs处理ipython输出的ansi控制序列的能力。如果它仍然无法正常工作,那么您可能需要记录错误报告。

还可以采取一些措施来解决这个问题。

  1. 尝试将--no-color-info开关添加到ipython。这将减少ipython输出的控制字符数量,这限制了我们的问题。
  2. 考虑使用python而不是ipython作为劣质过程。你看到的问题是由于ipython使用ansi控制字符来提供更好的shell。但是,emacs真的是你的shell,你可能最好让emacs处理界面,只使用更简单的劣质外壳
  3. Emacs Wiki对如何设置强大的python开发环境进行了相当详细的描述。使用简单的ipython / python劣质过程是最基本的方法。您可以更好地与其他一些软件包及时联系,以获得更完整的开发环境。