I've set up a virtual environment with venv and installed Ipython there via pip. On the terminal it works. Now, in my init.el, I have

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

(defun my-python-mode-setup ()
  (setq-local company-backends
              (append '((company-anaconda)) company-backends)))

(add-hook 'python-mode-hook 'my-python-mode-setup)

When I run Python after having pythonic-activated my virtual environment I get the following messages

Making python-shell-interpreter local to *Python* while let-bound!
Making python-shell-interpreter-args local to *Python* while let-bound!
Sent python-shell-completion-setup-code
Sent python-ffap-setup-code
Sent python-eldoc-setup-code

And the console looks like this (there are escape characters before square brackets that here aren't shown):

Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.

   ...: 28eJ''', 'exec'));[26D
[?1l[6n[?2004h[?25l[?7l[JIn [2]: [8D[8C[?7h[?12l[?25h[?25l[?7l[?7h[?12l[?25h

If I run-python from outside the virtual environment, Ipython launches and works flawlessly, but in that case it uses python2.7.

Emacs is v24.5.1, on Ubuntu 16.04. All packages are at the latest version from the Gnu repository, or from Melpa if only available there (anaconda-mode is 20171223.1118).


Referencing this issue from the elpy package, a solution to your problem may be adding the --simple-prompt and --pprint arguments to the python-shell-interpreter-args variable, like so:

(setq python-shell-interpreter-args "--simple-prompt --pprint")

The default prompt display for IPython doesn't play nicely with how the Emacs terminal displays it, which is why you are getting the crazy output.

Your Answer

