使用emacs ipython劣质Python时代码混乱

2024-09-30 01:21:19 发布

您现在位置:Python中文网/ 问答频道 /正文

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

但是,当我编辑一个python脚本并使用Ctrl-Enter将其发送给下级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

在这个低级python中按Enter时,它显示:

^{pr2}$

我将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\u US:en“&;emacs”$,无法帮助解决混乱的代码。在

我也试试python-模式.et或者emacs中的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

Tags: ofinforobjectipythonhelperrorcn
2条回答

从输出和错误消息来看,由于某些原因,您的设置没有处理ipython使用的ansi转义序列。假设您使用的是pythong模式,请确保您具有以下特性

(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来处理接口,只使用一个更简单的劣质shell
  3. emacswiki对如何设置强大的python开发环境有相当详细的描述。使用简单的ipython/python次进程是最基本的方法。为了获得一个更完整的开发环境,您最好及时使用其他一些包。在

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

相关问题 更多 >

    热门问题