ob-ipython icon indicating copy to clipboard operation
ob-ipython copied to clipboard

emacs hangs if python block is not executed

Open kdheepak opened this issue 10 years ago • 14 comments

If I run just an ipython session (example I've used below), I get the following warning and emacs hangs

Warning (python): Your ‘python-shell-interpreter’ doesn’t seem to support readline, yet ‘python-shell-completion-native’ was t and "python" is not part of the ‘python-shell-completion-native-disabled-interpreters’ list.  Native completions have been disabled locally. 
#+BEGIN_SRC ipython :session mysession :exports both
  def foo(x):
      return x + 9

 [foo(x) + 7 for x in range(7)]
#+END_SRC

However, if I run a python session before that, I get the same warning but emacs doesn't hang and I get results.

#+begin_src python :results output :session
print "There are %d hours in a week." % (7*24)
2**10
#+end_src

#+RESULTS:
: Python 2.7.9 |Anaconda 2.1.0 (x86_64)| (default, Dec 15 2014, 10:37:34) 
: [GCC 4.2.1 (Apple Inc. build 5577)] on darwin
: Type "help", "copyright", "credits" or "license" for more information.
: Anaconda is brought to you by Continuum Analytics.
: Please check out: http://continuum.io/thanks and https://binstar.org
: There are 168 hours in a week.
: python.el: native completion setup loaded
: 1024


#+BEGIN_SRC ipython :session mysession :exports both
  def foo(x):
      return x + 9

 [foo(x) + 7 for x in range(7)]
#+END_SRC

#+RESULTS:
: [16, 17, 18, 19, 20, 21, 22]

Any idea what is going on here?

Edit - I also get the following message when it hangs : "Shell native completion is disabled, using fallback". I'm using Jupyter v4.0

kdheepak avatar Sep 01 '15 19:09 kdheepak

Does this happen with the latest version of ob-ipython?

gregsexton avatar Sep 23 '15 16:09 gregsexton

I fixed a bunch of problems with Jupyter 4.

gregsexton avatar Sep 23 '15 16:09 gregsexton

I don't know if this is a similar issue. However, if I don't execute:

#+BEGIN_SRC python 
return 1+1   
#+END_SRC

#+BEGIN_SRC *python* :session
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
%load_ext version_information
#+END_SRC

and then change it to

#+BEGIN_SRC *ipython* :session
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
%load_ext version_information  
#+END_SRC

I get the following: Writing to process: input/output error, Python

With the following versions:

ob-ipython 20150926.712 Python 2.7.10 64bit [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] IPython 4.0.0 OS Darwin 14.5.0 x86_64 i386 64bit

If I also don't add the python block before the ipython block (that needs to first be evaluated as python) then I get bad file descriptor.

bakirtzisg avatar Oct 06 '15 17:10 bakirtzisg

Still getting the original issue on Windows 7 with : ob-ipython 20150926.712, emacs 25, Ipython 4.0.0, Python 3.4.3, Anaconda 2.3 .0 64 bit.

subhacom avatar Oct 06 '15 18:10 subhacom

Hi, I got the same warning message.

yitang avatar Jan 15 '16 19:01 yitang

The problem here is exactly the same as @kdheepak89 described with emacs 25.1.50.1 and the latest ob-ipython and ipython 4.0.1

Yevgnen avatar Jan 28 '16 06:01 Yevgnen

I got the same waning too. Here is my situation: Emacs version: GNU Emacs 24.5.1 (x86_64-apple-darwin15.2.0, NS apple-appkit-1404.34) python.el: Author: Fabián E. Gallina Version: 0.25.1

With 'python-shell-interpreter ' set to 'ipython' (either explicitly set by myself or set by Elpy), when I sent execute the buffer of a .py file, I will get the same warning. Nevertheless, the tab completion still works in contrary to the warning message. AND of course I have the similar problem in SRC block in org mode.

If I switch python-mode to the one in python-mode.el, the problem disappears but python SRC in org mode with :session stops working. So I guess it should not be a problem of Elpy or ob-ipython but rather one in the python.el

fanpeng-kong avatar Feb 09 '16 12:02 fanpeng-kong

Hi guys, I just tested (setq python-shell-completion-native-enable nil) fix the problem for me @gregsexton

fanpeng-kong avatar Feb 10 '16 12:02 fanpeng-kong

Thanks for pointing out a fix. This is annoying. Currently I'm not sure what the best way forward is. Will keep thinking about it.

gregsexton avatar Apr 24 '16 20:04 gregsexton

Under ipython 5 with the latest code, this doesn't seem to affect anything anymore - no pauses - but there is an annoying popup.

This is what I get.

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’
Warning (python): Your ‘python-shell-interpreter’ doesn’t seem to support readline, yet ‘python-shell-completion-native’ was t and "jupyter" is not part of the ‘python-shell-comple\tion-native-disabled-interpreters’ list.  Native completions have been disabled locally.

Tried this:

(defun ob-ipython--create-repl (name)
  ;; TODO: hack while we wait on
  ;; https://github.com/jupyter/jupyter_console/issues/93
  (let ((prev (getenv "JUPYTER_CONSOLE_TEST"))
        (python-shell-completion-native-enable nil)
        (python-shell-completion-native-disabled-interpreters '("jupyter")))
    (setenv "JUPYTER_CONSOLE_TEST" "1")
    (run-python (s-join " " (ob-ipython--kernel-repl-cmd name)) nil nil)
    (setenv "JUPYTER_CONSOLE_TEST" prev)
    (format "*%s*" python-shell-buffer-name)))

Still get the warning. Open to suggestions here...

gregsexton avatar Sep 24 '16 17:09 gregsexton

I have the same problem with emacs & python3.5, any news about that?

ryukinix avatar Oct 26 '16 21:10 ryukinix

You can disable warnings with

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

ChillarAnand avatar Nov 04 '16 14:11 ChillarAnand

Unfortunately I receive the same warning: image

ryukinix avatar Nov 04 '16 23:11 ryukinix

I got a similar problem to @kdheepak. If I directly run ipython session, emacs freezes forever; but if I first run python and then ipython, it worked.

gnohz avatar May 28 '17 19:05 gnohz