Elpy: Weird formatting with ipython?

Created on 24 Apr 2016  路  8Comments  路  Source: jorgenschaefer/elpy

Hi,

I'm using Emacs 24.5.1 on Windows 7. I have Anacondas 64 bit with python3 as the default. I am using the bleeding edge version of elpy, and manually installed it and its dependencies. When evaluate (elpy-use-ipython) to use ipython, I get the following formatting issue in the *Python* buffer within emacs. Any thoughts on how I could fix this? Thanks.

Python 3.5.1 |Anaconda 2.5.0 (64-bit)| (default, Jan 29 2016, 15:01:46) [MSC v.1900 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython 4.0.3 -- 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.

In [1]: 
In [2]: x
Question

Most helpful comment

The following seems to work. It's from the link provided by @jorgenschaefer :

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

All 8 comments

Hello! This is ipython trying to use color codes in Emacs, while Emacs is not a real terminal. Can you try and add the following to your init file and see if that fixes things?

(setq ansi-color-for-comint-mode t)

Yes, this fixes my formatting issue. Thank you.

You're welcome, and enjoy Elpy :-)

I have added the (setq ansi-color-for-comint-mode t), but my situation can't be changed.

Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25)
Type "copyright", "credits" or "license" for more information.

IPython 5.0.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.

^[[J^[[?7h^[[?12l^[[?25h^[[?2004l
^[[J^[[?7h^[[?12l^[[?25h^[[?2004l
^[[?12l^[[?25h
^[[?12l^[[?25h
^[[?12l^[[?25h
^[[?12l^[[?25h
^[[?12l^[[?25h
^[[?12l^[[?25h
^[[?12l^[[?25h

Here is my config.

Elpy Configuration

Virtualenv........: None
RPC Python........: 3.5.2 (/Library/Frameworks/Python.framework/Versions/3.5/bin/python3)
Interactive Python: ipython (/Library/Frameworks/Python.framework/Versions/3.5/bin/ipython)
Emacs.............: 24.5.1
Elpy..............: 1.11.0
Jedi..............: 0.9.0
Rope..............: Not found (0.10.3 available)
Importmagic.......: 0.1.7
Autopep8..........: 1.2.4
Yapf..............: 0.10.0
Syntax checker....: pyflakes (/usr/local/bin/pyflakes)

You have not activated a virtual env. While Elpy supports this, it is
often a good idea to work inside a virtual env. You can use M-x
pyvenv-activate or M-x pyvenv-workon to activate a virtual env.

The directory ~/.local/bin/ is not in your PATH. As there is no active
virtualenv, installing Python packages locally will place executables
in that directory, so Emacs won't find them. If you are missing some
commands, do add this directory to your PATH.

Options

Square brackets indicate buttons; type RET or click mouse-1 on a
button to invoke its action. Invoke [+] to expand a group, and [-] to
collapse an expanded group. Invoke the [Group], [Face], and [Option]
buttons below to edit that item in another window.

[+]-- [Group] Elpy
[+]-- [Group] Python
[+]-- [Group] Virtual Environments (Pyvenv)
[+]-- [Group] Completion (Company)
[+]-- [Group] Call Signatures (ElDoc)
[+]-- [Group] Inline Errors (Flymake)
[+]-- [Group] Snippets (YASnippet)
[+]-- [Group] Directory Grep (rgrep)
[+]-- [Group] Search as You Type (ido)

This didn't work for me either. The variable has been set properly as well (output of describe-variable):

ansi-color-for-comint-mode is a variable defined in `ansi-color.el'.
Its value is t

Running IPython without elpy within emacs doesn't cause this issue for me. I do this by running ansi-term and when prompted for a shell I enter 'ipython'. This runs the same version of ipython as elpy.

This issue is with Elpy 1.12.0 and IPython 5.0.0


A workaround

If you create the python buffer before hand, then elpy will connect to that buffer. Here are the steps

  • M-x ansi-term

    • Enter "ipython" when prompted

  • M-x rename-buffer

    • Set the name to "_Python_"

IPython changed the way it handles prompts, completely ignoring whether the terminal it talks to can actually handle it. You have to configure it to not do that. See e.g. https://emacs.stackexchange.com/questions/24453/weird-shell-output-when-using-ipython-5

Running the interactive ipython inside ansi-term looks quite attractive. Is there a way to configure Elpy to do just this instead of starting it manually and then renaming to "Python" as suggested by @gnsiva?

The following seems to work. It's from the link provided by @jorgenschaefer :

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SergiyKolesnikov picture SergiyKolesnikov  路  3Comments

kirk86 picture kirk86  路  5Comments

rthompsonj picture rthompsonj  路  6Comments

kapilsh picture kapilsh  路  3Comments

mdk2029 picture mdk2029  路  5Comments