gregsexton / ob-ipython

org-babel integration with Jupyter for evaluation of (Python by default) code blocks
739 stars 109 forks source link

IPython 5 Prompt detection #89

Closed salotz closed 4 years ago

salotz commented 7 years ago

Just installed ob-python and I have the fancy new IPython prompt which I think is confusing things. When I execute a cell C-c C-c it starts the *Python* buffer which has the normal IPython In [?]: prompt but I get this warning

Warning (emacs): 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'

Nothing is hanging I don't think and I imagine it has something to do with this: https://github.com/gregsexton/ob-ipython/commit/cfdd9c00e6286d31d647defdb813b7aabfadcbff

I'm using version 20160918.1001 from MELPA, Jupyter 4.1.1, Jupyter console 5.0.0, IPython 5.1.0, and Python 3.5.2.

I'll try and install manually with that commit and see if that fixes it if I have time later.

xin-jin commented 7 years ago

I got the same warning message, though my simple script ran OK.

pboynton commented 7 years ago

The simple yet not so satisfying solution I found, thanks to elpy issue 733, is to just get rid of the warning since I haven't found any issue with actually running my code. This command in .emacs will do it:

(setq python-shell-prompt-detect-failure-warning nil)

I tried the solution further down in that issue as well but it didn't work for me. I'm running Windows 10, Emacs 24.5.1, and using version 20160918.1001 of ob-ipython from MELPA as you are. This warning came up for the following 2 different Anaconda configurations, the first of which used Ipython 4 so it can't be related to Ipython 5 in particular.

It must have to do with the new version of ob-ipython because it only appeared right after I updated it on MELPA and it could be related to python-eldoc-setup-code as that is what seems to trigger the warning.

deisi commented 7 years ago

Hey I have the same, on windows 7 and python 3.5. For me this has the effect, that autocompletion doesn't work.

salotz commented 7 years ago

Recent updates to my emacs packages seem to have fixed my issue. It was probably a dependency as ob-ipython was not updated.

deisi commented 7 years ago

@salotz Do you run the git version or melpa

salotz commented 7 years ago

@deisi the Melpa one

deisi commented 7 years ago

Hmm I have the same one, and emacs was setup freshly on Monday, So updateing doesn't solve it for me then....

On 27.10.2016 16:33, salotz wrote:

@deisi https://github.com/deisi the Melpa one

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/gregsexton/ob-ipython/issues/89#issuecomment-256658934, or mute the thread https://github.com/notifications/unsubscribe-auth/AFL2NMQQ6Fa4TjBc3BOOlBvuAhtT6GNbks5q4LZDgaJpZM4KPVjZ.

salotz commented 7 years ago

I am on Ubuntu 16.04 and one the updates for that might have done it as well. What emacs version are you using? I am on 24.5.1.

pboynton commented 7 years ago

I'm fully updated on MELPA and I'm still getting the warning. Could be updates on Ubuntu as you said.

deisi commented 7 years ago

I use Arch Linux and Windows.

I see the messages on both systems. emacs is 24.5.1 in both cases.

On 27.10.2016 23:26, Paul Boynton wrote:

I'm fully updated on MELPA and I'm still getting the warning. Could be updates on Ubuntu as you said.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/gregsexton/ob-ipython/issues/89#issuecomment-256774687, or mute the thread https://github.com/notifications/unsubscribe-auth/AFL2NB42-LU8T6p1O2uiCetrV7pkeBd0ks5q4Rb5gaJpZM4KPVjZ.

salotz commented 7 years ago

@deisi Are you just talking about autocompletion? Do you mean autocompletion in the org src buffer or at the ipython shell buffer? In any case that was not the original reason I started this issue.

deisi commented 7 years ago

@salotz I think the stuff with the auto-completion is kind of working now. (I don't really know for the windows machine, because I work in a VM at the moment). The problem was, that I didn't understand, one had to execute an ipython code-block first, before the auto completion feature becomes available. Now it is usually working as expected, though it often opens a new auto completion buffer instead of showing a drop-down table. Up to no I don't always fully understand what is going on, but I'm fairly knew to all this. I will see with time. With all the different buffers and minor-modes involved, it can get quite confusing, why what is happening.

deisi commented 7 years ago

In any case that was not the original reason I started this issue. I know, it was rather meant as a side note. I am still experimenting with org-mode and ipython, and I was not sure what to expect from the auto-completion feature. I'm used to jupiter notebooks and so I assumed it to "just work" by pressing tab, but apparently one has to get a bit used to it before it becomes easy. Anyway, we don't need to discuss this here. I will open an issue, when I can formulate the problem more precisely.

On 28.10.2016 16:08, salotz wrote:

@deisi https://github.com/deisi Are you just talking about autocompletion? Do you mean autocompletion in the org src buffer or at the ipython shell buffer? In any case that was not the original reason I started this issue.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/gregsexton/ob-ipython/issues/89#issuecomment-256929555, or mute the thread https://github.com/notifications/unsubscribe-auth/AFL2NO9e61018L52SrhkiI0oBcCKLYYtks5q4gH0gaJpZM4KPVjZ.

jwhendy commented 7 years ago

I'm also on arch linux here. I found that if I change ob-ipython-command from the default "jupyter" to "ipython3", the mentioned warning goes away.

I'm using the git version, not melpa. Is this expected (I noticed there's another branch, so maybe I'm not using this correctly)?

$ emacs --version
GNU Emacs 25.2.1

$ python --version
Python 3.6.1

$ ipython3 --version
5.3.0

$ jupyter --version
4.3.0

Default process list when I get the warnings with jupyter::

Python          run     *Python*        /dev/pts/3   jupyter console --existing emacs-default.json
client-driver   run     *ob-ipython-... /dev/pts/1   /usr/bin/python -- /home/jwhendy/.elisp/ob-ipython/driver.py --port 9988
kernel-default  run     *ob-ipython-... /dev/pts/2   /usr/bin/python -- /home/jwhendy/.elisp/ob-ipython/driver.py --conn-file emacs-default.json

Process list with ipython3 as command (no warnings):

Python          run     *Python*        /dev/pts/3   ipython3 console --existing emacs-default.json
client-driver   run     *ob-ipython-... /dev/pts/1   /usr/bin/python -- /home/jwhendy/.elisp/ob-ipython/driver.py --port 9988
kernel-default  run     *ob-ipython-... /dev/pts/2   /usr/bin/python -- /home/jwhendy/.elisp/ob-ipython/driver.py --conn-file emacs-default.json

Minimal config used with emacs -Q to test:

;; load paths
(add-to-list 'load-path "~/.elisp/org/lisp/")
(add-to-list 'load-path "~/.elisp/org/contrib/lisp")
(add-to-list 'load-path "~/.elisp/ess/lisp/")
(add-to-list 'load-path "~/.elisp/ob-ipython/")
(add-to-list 'load-path "~/.elisp/f.el/")
(add-to-list 'load-path "~/.elisp/s.el/")
(add-to-list 'load-path "~/.elisp/dash.el/")

(require 'org)

(require 'ob-ipython)
(setq ob-ipython-command "ipython3")

;; setup babel languages
(org-babel-do-load-languages
 'org-babel-load-languages
 '((ipython . t)))

Edit: removed some comments about elpa packages I thought might have been causing an error. After more fiddling, I think this was on my end and I don't get them anymore with the config above. Removing to avoid potential confusion/for brevity.

alastairdb commented 7 years ago

My hack to get a usable REPL with IPython > 5:

diff --git a/ob-ipython.el b/ob-ipython.el
index d27c920..157b198 100644
--- a/ob-ipython.el
+++ b/ob-ipython.el
@@ -139,8 +139,16 @@
     (format "emacs-%s.json" name)))

 (defun ob-ipython--kernel-repl-cmd (name)
-  (list ob-ipython-command "console" "--existing"
-        (ob-ipython--kernel-file name)))
+  (with-temp-buffer
+    (call-process ob-ipython-command nil t nil "console" "--version")
+    (goto-char (point-max))
+    (forward-line -1)
+    (beginning-of-line)
+    (if (>= (string-to-number (char-to-string (char-after))) 5)
+   (list ob-ipython-command "console" "--simple-prompt" "--existing"
+         (ob-ipython--kernel-file name))
+      (list ob-ipython-command "console" "--existing"
+       (ob-ipython--kernel-file name)))))

 (defun ob-ipython--create-process (name cmd)
   (apply 'start-process name (format "*ob-ipython-%s*" name) (car cmd) (cdr cmd)))
impaktor commented 5 years ago

I'm experiencing the samme issue (also on Arch Linux), but this fixed it for me:

(setq ob-ipython-command "ipython3")

But I do get deprecation warning that:

[TerminalIPythonApp] WARNING | Subcommand `ipython console` is deprecated and will be removed in future versions.
[TerminalIPythonApp] WARNING | You likely want to use `jupyter console` in the future
Jupyter console 6.0.0

Python 3.7.1 (default, Oct 22 2018, 10:41:28) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.1.1 -- An enhanced Interactive Python. Type '?' for help.
salotz commented 4 years ago

stale