You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add multiline coding in ipython 5 with --simple-prompt #9816
As emacs user I often use emacs repl with ipython, but after update to ipython 5 I need to use --simple-prompt flag for my work. But when I try to create new def or class I get this error message
In [1]: defnew():
File"<ipython-input-1-ce93a60072ff>", line1defnew():
^SyntaxError: unexpectedEOFwhileparsing
FYI: prompt_toolkit 1.0.4 has been released today, it has one improvement that should make prompt_toolkit render at least slightly better in emacs-term. Can you have a try?
Hello, I have updated to prompt_toolkit 1.0.4 with emacs 25.0.95.1 and ipython 5.0.0. For some reason, running just ipython defaults to the simple-prompt and I am having trouble testing with prompt_toolkit - which is weird and I cannot figure out why.
However, running jupyter console still returns the same error it was returning before updating prompt_toolkit. Not sure if this helps or just confuses things further.
Here is the traceback
Traceback (most recent call last):
File "C:\Users\A6419643\AppData\Local\Continuum\Miniconda3\Scripts\jupyter-console-script.py", line 5, in <module>
sys.exit(jupyter_console.app.main())
File "C:\Users\A6419643\AppData\Local\Continuum\Miniconda3\lib\site-packages\jupyter_core\application.py", line 267, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "C:\Users\A6419643\AppData\Local\Continuum\Miniconda3\lib\site-packages\traitlets\config\application.py", line 595, in launch_instance
app.initialize(argv)
File "<decorator-gen-114>", line 2, in initialize
File "C:\Users\A6419643\AppData\Local\Continuum\Miniconda3\lib\site-packages\traitlets\config\application.py", line 74, in catch_config_error
return method(app, *args, **kwargs)
File "C:\Users\A6419643\AppData\Local\Continuum\Miniconda3\lib\site-packages\jupyter_console\app.py", line 137, in initialize
self.init_shell()
File "C:\Users\A6419643\AppData\Local\Continuum\Miniconda3\lib\site-packages\jupyter_console\app.py", line 110, in init_shell
client=self.kernel_client,
File "C:\Users\A6419643\AppData\Local\Continuum\Miniconda3\lib\site-packages\traitlets\config\configurable.py", line 412, in instance
inst = cls(*args, **kwargs)
File "C:\Users\A6419643\AppData\Local\Continuum\Miniconda3\lib\site-packages\jupyter_console\ptshell.py", line 252, in __init__
self.init_prompt_toolkit_cli()
File "C:\Users\A6419643\AppData\Local\Continuum\Miniconda3\lib\site-packages\jupyter_console\ptshell.py", line 404, in init_prompt_toolkit_cli
self.pt_cli = CommandLineInterface(app, eventloop=self._eventloop)
File "C:\Users\A6419643\AppData\Local\Continuum\Miniconda3\lib\site-packages\prompt_toolkit\interface.py", line 80, in __init__
self.output = output or create_output()
File "C:\Users\A6419643\AppData\Local\Continuum\Miniconda3\lib\site-packages\prompt_toolkit\shortcuts.py", line 114, in create_output
return Win32Output(stdout)
File "C:\Users\A6419643\AppData\Local\Continuum\Miniconda3\lib\site-packages\prompt_toolkit\terminal\win32_output.py", line 80, in __init__
info = self.get_win32_screen_buffer_info()
File "C:\Users\A6419643\AppData\Local\Continuum\Miniconda3\lib\site-packages\prompt_toolkit\terminal\win32_output.py", line 150, in get_win32_screen_buffer_info
raise NoConsoleScreenBufferError
prompt_toolkit.terminal.win32_output.NoConsoleScreenBufferError: No Windows console found. Are you running cmd.exe?
Process Python exited abnormally with code 1
In comint mode you only get one line, but you can use one of the send-buffer-to-shell commands in python-mode / elpy to send a buffer to the interpreter. That plus an org-mode source region or just a /tmp/scratch.py file is how I do multi-line editing these days.
@AndreaOrru Pretty sure the change is moving from readline to prompt toolkit which lots some of the special-cased work arounds on both sides.
I strongly suggest opening /tmp/scratch.py, writing your multi-line stuff there (or using org-mode + source blocks), and shipping it to the shell via send-buffer-to-shell (bound to C-c C-c by elpy).
whenever I try to send multiline code ending with ':' character. Sending whole buffer works just fine but individual lines are problematic, which makes testing code very difficult.
the work around you use above makes the ipython prompt work in emacs, but it does not allow multiline editing. There is currently no solution that allows multiline editing in an ipython shell in emacs.
If you want multiline editing, I would follow @tacaswell's advice above using python buffers, etc.
So why you couldn`t have both readline and promt_toolkit and switching them using some flags? Even if you won`t support readline you can at least leave it as it is. This is huge regression for many users and I don`t think promt_toolkit is much better then readline. It isn`t work with ipdb also.
@ajsteven130 Thanks for great advice @ALL Using python instead of ipython5 with emacs seems like a better solution for now.
What works for me is that I can copy now multiple lines into the python buffer and they get executed.
That wasn't the case when using ipython. However, line-by-line sending does not work in Emacs(elpy) at the moment of writing I encounter this bug #907 and suggested alternative C-M-x does not work as expected as well. Kind of stucked now with copying blocks of code, but better than nothing.
iPython 5.1 in Windows (7) Emacs 25.1.2 run-python.
The trick to use an elpy buffer to send to the *Python* buffer works well - thanks.
None of the %magic% functions work and, in particular, I'd like %recall. Backed up briefly to iPython 4.2.1 however this put me back to no Output at all so that's not an option.
What programming changes would be involved to make %recall work?
nope, no clue, unfortunately. I still have an old IPython installed when I need to get a lot of interactive work done because it respects .inputrc and I haven't made the time to make prompt_toolkit act the ways readline does. The functionality provided by --TerminalInteractiveShell.editing_mode=vi is inconsistent enough with muscle memory that it makes it more frustrating than just using the default mode, so I stick with that when I'm in IPython 5 these days.
I upgraded to Ipython5 and downgraded to Ipython4 with same Emacs issue. If everything works same, I could just stick with Ipython4 but something is changed and work weird now.
When I define simple function and execute it twice in ipython, it shows like below:
I just want to mention that if you would like the old (IPython <= 4.x) readline interface, it is now available separately as rlipython.
pip install rlipython
python -c "import rlipython as r; r.install()"
Right now, it only works in IPython 6.0 (Python 3), but it will also work in Python 2 with the next IPython 5 release (5.4).
I suspect, but have not verified, that the style of interaction with emacs that used to work in IPython <= 4 should work again with rlipython. If not, file an issue there and I can take a look.
Reacted by Braham Snyder, Vitalii and Ganesh Krishnan
Looks like something is broken on the process to upgrade and downgrade ipython.
I found simple-prompt option does not support mulitline coding too late, so I had to downgrade ipython on my home PC, company PC and server PC. Now all ipython from those computers shows same error.
I hope anyhow this issue will be solved soon. Thanks a lot.
In case of my emacs + ipython error, It is solved when I try python-mode package instead of built-in emacs python package. It works as usual when I start ipython using python-mode package.(w/ Ipython 4.2.1 version) I hope this would be helpful for anybody having same problem with me.
Thanks again for all contributing to ipython.
+) One more update, my error case has to do with company package. It works clearly if I start ipython with global-company-mode disabled.
@ivanov@Carreau I've been using --simple-prompt which currently allows some kind of primitive multiline editing in emacs although I've always missed the superior pt capabilities since I started running my repls inside emacs. So I googled for alternatives and ended up here. After testing rlipython I'm unable to find any relevant differences vs plain --simple-prompt, at least for multiline editing. What would be rlipython selling points for emacs users? Do you know?
@memeplex - does the emacs repl allow you to use up arrows to cycle in history? --simple-prompt does not support that, but that's the only thing that comes immediately to mind. I guess the lack of that feature also implies that you do not get history across sessions.
Activity
takluyver commentedon Jul 28, 2016
The simple-prompt option doesn't support multi-line input, but I thought Emacs 'inferior-shell' magic was working round that. @tacaswell ?
Crandel commentedon Jul 28, 2016
In ansi-term ipython work well, but I need REPL. Standart python interactive shell works fine, but I really miss %magic%
jonathanslenders commentedon Aug 3, 2016
FYI: prompt_toolkit 1.0.4 has been released today, it has one improvement that should make prompt_toolkit render at least slightly better in emacs-term. Can you have a try?
takluyver commentedon Aug 3, 2016
In the context of IPython, that means try without
--simple-prompt, so that it uses prompt_toolkit.@tacaswell might also be interested in testing.
ajsteven130 commentedon Aug 4, 2016
Hello, I have updated to prompt_toolkit 1.0.4 with emacs 25.0.95.1 and ipython 5.0.0. For some reason, running just ipython defaults to the simple-prompt and I am having trouble testing with prompt_toolkit - which is weird and I cannot figure out why.
However, running
jupyter consolestill returns the same error it was returning before updating prompt_toolkit. Not sure if this helps or just confuses things further.Here is the traceback
takluyver commentedon Aug 4, 2016
I'd guess that maybe our checks for a terminal fail, so it falls back to simple-prompt automatically.
@jonathanslenders - I take it that traceback is not what you were expecting! Is there anything else the Windows+Emacs users should try?
osdf commentedon Aug 29, 2016
Any progress on this issue?
tacaswell commentedon Aug 29, 2016
Sorry, I missed the ping on this in July.
In comint mode you only get one line, but you can use one of the
send-buffer-to-shellcommands in python-mode / elpy to send a buffer to the interpreter. That plus an org-mode source region or just a/tmp/scratch.pyfile is how I do multi-line editing these days.AndreaOrru commentedon Oct 16, 2016
This is pretty huge for us Emacs users. :(
Why does it work on iPython 4.x? What changed exactly?
tacaswell commentedon Oct 16, 2016
@AndreaOrru Pretty sure the change is moving from readline to prompt toolkit which lots some of the special-cased work arounds on both sides.
I strongly suggest opening
/tmp/scratch.py, writing your multi-line stuff there (or using org-mode + source blocks), and shipping it to the shell viasend-buffer-to-shell(bound toC-c C-cby elpy).mashu commentedon Oct 26, 2016
Hi guys,
I have the following problem using Emacs25 with ipython 5, as it uses some strange colours. I have this as walk-around
but then I get this error as in reported bug
whenever I try to send multiline code ending with ':' character. Sending whole buffer works just fine but individual lines are problematic, which makes testing code very difficult.
Please help.
ajsteven130 commentedon Oct 26, 2016
hi @mashu,
the work around you use above makes the ipython prompt work in emacs, but it does not allow multiline editing. There is currently no solution that allows multiline editing in an ipython shell in emacs.
If you want multiline editing, I would follow @tacaswell's advice above using python buffers, etc.
Crandel commentedon Oct 26, 2016
So why you couldn`t have both readline and promt_toolkit and switching them using some flags? Even if you won`t support readline you can at least leave it as it is. This is huge regression for many users and I don`t think promt_toolkit is much better then readline. It isn`t work with ipdb also.
mashu commentedon Oct 26, 2016
@ajsteven130 Thanks for great advice
@ALL Using python instead of ipython5 with emacs seems like a better solution for now.
What works for me is that I can copy now multiple lines into the python buffer and they get executed.
That wasn't the case when using ipython. However, line-by-line sending does not work in Emacs(elpy) at the moment of writing I encounter this bug #907 and suggested alternative C-M-x does not work as expected as well. Kind of stucked now with copying blocks of code, but better than nothing.
17 remaining items
patfla commentedon Jan 26, 2017
iPython 5.1 in Windows (7) Emacs 25.1.2 run-python.
The trick to use an elpy buffer to send to the *Python* buffer works well - thanks.
None of the %magic% functions work and, in particular, I'd like %recall. Backed up briefly to iPython 4.2.1 however this put me back to no Output at all so that's not an option.
What programming changes would be involved to make %recall work?
fperez commentedon Feb 21, 2017
I'm curious if @ivanov might have some ideas on the vim front (I know the Emacs issues are separate)?
ivanov commentedon Feb 26, 2017
nope, no clue, unfortunately. I still have an old IPython installed when I need to get a lot of interactive work done because it respects
.inputrcand I haven't made the time to make prompt_toolkit act the ways readline does. The functionality provided by--TerminalInteractiveShell.editing_mode=viis inconsistent enough with muscle memory that it makes it more frustrating than just using the default mode, so I stick with that when I'm in IPython 5 these days.ramsayleung commentedon Apr 26, 2017
Ipython6 is released, is this issue fixed?
tttuuu888 commentedon May 8, 2017
I upgraded to Ipython5 and downgraded to Ipython4 with same Emacs issue. If everything works same, I could just stick with Ipython4 but something is changed and work weird now.
When I define simple function and execute it twice in ipython, it shows like below:
It works fine if I execute ipython in terminal.
ivanov commentedon May 17, 2017
I just want to mention that if you would like the old (IPython <= 4.x) readline interface, it is now available separately as rlipython.
Right now, it only works in IPython 6.0 (Python 3), but it will also work in Python 2 with the next IPython 5 release (5.4).
I suspect, but have not verified, that the style of interaction with emacs that used to work in IPython <= 4 should work again with rlipython. If not, file an issue there and I can take a look.
tttuuu888 commentedon May 18, 2017
Thanks for your suggestion @ivanov but unfortunately I have a same issue even after rlipython installed.
Error messages are shown as below:
Looks like something is broken on the process to upgrade and downgrade ipython.
I found simple-prompt option does not support mulitline coding too late, so I had to downgrade ipython on my home PC, company PC and server PC. Now all ipython from those computers shows same error.
I hope anyhow this issue will be solved soon. Thanks a lot.
tttuuu888 commentedon May 18, 2017
In case of my emacs + ipython error, It is solved when I try python-mode package instead of built-in emacs python package. It works as usual when I start ipython using python-mode package.(w/ Ipython 4.2.1 version) I hope this would be helpful for anybody having same problem with me.
Thanks again for all contributing to ipython.
+) One more update, my error case has to do with company package. It works clearly if I start ipython with global-company-mode disabled.
infinity0 commentedon May 22, 2017
This is preventing the cantor sage backend from working.
Carreau commentedon May 25, 2017
You most likely want to have a look at rlipython, it allows to re-use readline as a backend and should work way better with emacs.
Force ipython3 REPL.
memeplex commentedon Jul 30, 2018
@ivanov @Carreau I've been using
--simple-promptwhich currently allows some kind of primitive multiline editing in emacs although I've always missed the superior pt capabilities since I started running my repls inside emacs. So I googled for alternatives and ended up here. After testing rlipython I'm unable to find any relevant differences vs plain--simple-prompt, at least for multiline editing. What would be rlipython selling points for emacs users? Do you know?ivanov commentedon Jul 30, 2018
@memeplex - does the emacs repl allow you to use up arrows to cycle in history?
--simple-promptdoes not support that, but that's the only thing that comes immediately to mind. I guess the lack of that feature also implies that you do not get history across sessions.memeplex commentedon Jul 30, 2018
Up/down arrows work for moving between lines in a multiline input but not for history cycling.