I'm trying to get Emacs to start ipython from Anaconda.

I have two systems which are not identical so figured setting symbolic links in ~/bin/ipython as I have ~/bin/ pre-pended to my $PATH would do the trick. It works on one system no problem but on the other no joy.

My ~/.emacs.d/settings/python-settings.el (sourced from ~/.emacs.d/init.el) has...

;; --------------------------------------

;; Set ipython as the default interpreter
(setq python-shell-interpreter "~/bin/ipython"
  python-shell-interpreter-interactive-args "-i --simple-prompt")

;; use flycheck not flymake with elpy
(when (require 'flycheck nil t)
  (setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
  (add-hook 'elpy-mode-hook 'flycheck-mode))
;; Try to add pylint rules 
(add-hook 'python-mode-hook
      (lambda ()
        (setq flycheck-python-pylint-executable "~/.local/bin/pylint")
        (setq flycheck-pylintrc "~/.emacs.d/settings/.pylintrc")))
;; enable autopep8 formatting on save
(require 'py-autopep8)
(add-hook 'elpy-mode-hook 'py-autopep8-enable-on-save)

When I try to run M-x run-python I get...

Searching for program: No such file or directory, \~/bin/ipython

..and yet at a terminal it is found and works...

$ which ipython
$ ls -l ~/bin/ipython
lrwxrwxrwx 1 neil.shephard domain users 77 Aug  7 09:51 
/home/slackline@mywork.com/bin/ipython -> /home/slackline@mywork.com/share/anaconda3/bin/ipython3
$  ipython
Python 3.6.6 |Anaconda custom (64-bit)| (default, Jun 28 2018, 17:14:51) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: 

It looks like the ~ is escaped and not interpreted correctly so I've tried with both an explicit path to the target of the symbolic link with...

(setq python-shell-interpreter "/home/slackline@mywork.com/share/anaconda3/bin/ipython"
  python-shell-interpreter-interactive-args "-i --simple-prompt")

...which results in...

/usr/bin/emacs: /home/slackline\@mywork.com/share/anaconda3/bin/ipython: No such file or directory
Process Python exited abnormally with code 127

...and the following under *Warnings*...

Warning (python): Python shell prompts cannot be detected.
If your emacs session hangs when starting python shells
recover with ‘keyboard-quit’ and then try fixing the
interactive flag for your interpreter by adjusting the
‘python-shell-interpreter-interactive-arg’ or add regexps
matching shell prompts in the directory-local friendly vars:
  + ‘python-shell-prompt-regexp’
  + ‘python-shell-prompt-block-regexp’
  + ‘python-shell-prompt-output-regexp’
Or alternatively in:
  + ‘python-shell-prompt-input-regexps’
  + ‘python-shell-prompt-output-regexps’

...which is a bit closer but iPython isn't starting under Emacs. I suspect it may have something to do with the weird @ in the path of my home directory but am unsure why "~/bin/ipython" is not correctly recognised under Emacs when it is from the command line.

Any suggestions as to whats going on and how to resolve them would be very welcome.


Finally solved this and it was as simple as setting...

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

Unfortunately I now get a different error....

error in process filter: ansi-color-filter-apply: Args out of range: "Python 3.6.6 |Anaconda custom (64-bit)| (default, Jun 28 2018, 17:14:51) 
Type 'copyright', 'credits' or 'license' for more information
IPython 6.5.0 -- An enhanced Interactive Python. Type '?' for help.

[6n[0m[0m[J[0;38;5;28mIn [[0;38;5;10;1m1[0;38;5;28m]: [8D[8C[0m[8D[J[0m[6n[0m[0m[J[0;38;5;28mIn [[0;38;5;10;1m1[0;38;5;28m]: [8D[8C[0m", 440

This looks like its related to custom PS1 issues and I've been having some problems with those which I've just solved.


I hope that this code will help you:

(defun ipython ()
  (ansi-term "/opt/anaconda/bin/ipython"))

(global-set-key (kbd "C-c I") 'ipython)
  • Thanks I'll give that a whirl after I've sorted out my ess issues
    – slackline
    Oct 2 '18 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.