Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enter in the IPython console inserts new line instead of executing current line after kernel restart #2696

Closed
derDavidT opened this issue Sep 16, 2015 · 62 comments

Comments

@derDavidT
Copy link

Recently I updated my anaconda package, which installed

ipython 4.0.0
ipython-qtconsole 4.0.1
spyder 2.3.6

After that, whenever I restart the ipython kernel in the qt-console (using ctrl + .), the console will not execute any command, e.g.:

Python 2.7.10 |Anaconda 2.3.0 (64-bit)| (default, May 28 2015, 16:44:52) [MSC v.1500 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.

IPython 4.0.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
%guiref   -> A brief reference about the graphical user interface.

In [1]: 1
   ...: 

I cannot reproduce this behavior when running ipython-qtconsole outside spyder, i.e. it works as expected. My current workaround ist closing the console, thus killing the kernel, and load a fresh one.

@bordingj
Copy link

Same behavior here (Python 3.4.3, Anaconda 2.3, Ubuntu 14.04)

@petebachant
Copy link

I'm getting the same behavior on Windows 10 x64, Python 3.

@ccordoba12
Copy link
Member

Thanks for reporting. I'll try to fix it for 2.3.7

@ccordoba12 ccordoba12 changed the title IPython 4.0.0 Qt-console stuck after kernel restart IPython 4.0.0 console stuck after kernel restart Sep 16, 2015
@ccordoba12
Copy link
Member

I can reproduce this error both in Python 2 and Python 3. No idea where it's coming from though :-)

@ccordoba12 ccordoba12 changed the title IPython 4.0.0 console stuck after kernel restart IPython console stuck after kernel restart Sep 28, 2015
@ccordoba12 ccordoba12 changed the title IPython console stuck after kernel restart IPython console prompt stuck after kernel restart Sep 28, 2015
@dluzenst
Copy link

Same problem with Spyder 2.3.6, PyQt4 4.10.4:

         platform : win-64
    conda version : 3.18.1

conda-build version : 1.17.0
python version : 2.7.10
requests version : 2.7.0

@ccordoba12
Copy link
Member

This is an upstream bug. i.e. meaning a bug that needs to be fixed in Jupyter qtconsole: https://github.com/jupyter/qtconsole

I'll try to submit a PR to qtconsole after releasing 2.3.7.

@ccordoba12 ccordoba12 modified the milestones: v2.3.7, v3.0 Oct 1, 2015
@ccordoba12 ccordoba12 changed the title IPython console prompt stuck after kernel restart Enter in the IPython console inserts new line instead of executing current line after kernel restart Nov 16, 2015
@Fishyman
Copy link

if you hold down shift and press enter it works fine (although not what we want)

@davidljung
Copy link

Anyone happen to know which qtconsole issue # is the cause of this?

@ccordoba12
Copy link
Member

I think this issue only happens in Spyder, so that's why it shouldn't be reported upstream.

The thing is we handle restarts differently than qtconsole, and that seems to have an impact on Enter (I don't know why! :-)

@davidljung
Copy link

The Enthought Canopy UI ipython console window doesn't have the issue - wonder if it is worth peeking into their source..

@ccordoba12
Copy link
Member

Yep, that's because (as said above) we handle kernel restarts differently from qtconsole (Canopy uses qtconsole almost unmodified as far as I know :-)

@davidljung
Copy link

I don't know how Canopy uses qtconsole, but their UI looks similar to Spyder, in that it has a movable/re-dockable panel with a variable explorer (and a more integrated debugger) etc. It certainly doesn't look anything like the minimal window that you see when just starting ipython qtconsole from the shell.

Given that from the end-user perspective, the way the ipython console appears in both Spyder and Canopy is almost identical, perhaps it would be worth looking into how Canopy achieved their integration in case it reveals any hints as to avoiding this enter<->shift-enter behavior reversal (or maybe not..). Just a thought (in absence of knowledge of either implementation).

@ccordoba12
Copy link
Member

The thing is we start our kernels through our Python console and later connect to them in our IPython console using its kernel-foo.json file.

That's necessary to connect IPython kernels to our Variable Explorer, but we plan to remove this workaround in Spyder 3.0 and connect to them directly.

That will also remove this bug :-)

@JanBenisek
Copy link

JanBenisek commented Jan 24, 2017

Python 2.7.12, Spyder 3.1, Windows 7 64bits, conda 4.3.7

I just received the same error - in the middle of executing it stopped working. Restart of kernel didn't help.

I found the cause. If I restart the console and do not execute this;

np.set_printoptions(linewidth=100, precision=4,suppress=True,threshold='nan')

it does work. But once I modify the print options for numpy arrays, the IPython console will not execute. I believe that the treshold='nan' is causing the problem.

@dhhagan
Copy link

dhhagan commented Feb 2, 2017

Any update on this? I still see it with the following:

Spyder=3.1.2
Qt=5.7.1 
PyQt5=5.7.1

ipykernel=4.5.2
ipython=5.2.1
qtconsole=4.2.1

@ghost
Copy link

ghost commented Feb 25, 2017

I was having this exactly problem (the issue's question), so I tried "Shift+Enter" in IPython console and it worked for me.

@zxzhijia
Copy link

I "shift+enter" and it froze. Everytime, I have to restart a new console.

@sgilber1
Copy link

sgilber1 commented Apr 6, 2017

I ran into the same problem.

I am using spyder 3.1.3
Python 3.6.1
Qt 5.8
PyQt5 5.8.2
Python 5.3.0
on a Mac (Darwin).

I found that the graphics backend determined whether I had the problem. When I used either the Qt5 or OS X backend I would have the problem. Plus it would toggle back and forth between giving me the problem or not every time I plotted a graph. When I used either the Tkinter or Inline backends, I didn't have the problem. I did not test either the Automatic or Qt4 backends.

@roversch
Copy link

Same here, with:

conda 4.3.17
Python 2.7.13
ipython 5.3.0

on Mac OSX 10.12

@stiebels
Copy link

stiebels commented Jun 12, 2017

Also got that (probably since upgrade to spyder 3.0) and its severely annoying:

spyder 3.1.4
conda 4.3.21
Python 3.5.2 (64-bit)
ipython 6.1.0

on Linux Mint 18

@idemockle
Copy link

This has happened many times to me today while working with pandas in Spyder 3.2 on Python 3.6/Win10. For me it was always after viewing a DataFrame with the head() method. CPU usage bumped up to 20ish% and Python's memory usage started steadily creeping up until I restarted the IPython kernel. I had to switch to a command prompt window because the embedded console in Spyder became essentially unusable.

@Khris777
Copy link

Khris777 commented Aug 11, 2017

I have been encountering this as well recently after some of the latest upgrades. Using Python 3.6.2 on Windows 10, IPython 6.1.0, and Spyder 3.6, I encounter the same behaviour using pandas and large dataframes. The console stays responsive when using the head() method, but the result eventually appears after hitting enter a few times and waiting. It's not limited to the head() method though. In other cases I have to put a line of code into an open file and hit F9 to get it to execute. This only seems to happen with very large data (right now having 11.6 million lines with 24 columns in memory).

I didn't encounter this before when working with Python 2 and IPython 5.

@ccordoba12
Copy link
Member

There are two reasons for this to happen:

  1. if you have complicated objects in the Variable Explorer (e.g. see issue Spyder stops executing commands if Variable explorer shows complicated objects #4221).
  2. If you're trying to inspect objects with a very big repr (this is a problem introduced by IPython, not by us).

We'll try to fix both issues in 3.2.2.

@crnprasanna
Copy link

I have the same issue and for me the following fixed on my mac,

  • I have 2 ipython shell opened, when I closed the other one, the other one worked

@Khris777
Copy link

I'm now on Spyder 3.2.3 and I still experience this issue.

@ccordoba12
Copy link
Member

@Khris777, is the code you posted on issue #5052 causing this problem?

@Khris777
Copy link

Khris777 commented Sep 18, 2017

@ccordoba12 , that code does not cause the problem anymore, that part has been fixed.

I'm still getting the problem however with large pandas dataframes, e.g. when using the head() method on a dataframe with millions of rows and lots of columns.

@ccordoba12
Copy link
Member

@Khris777, a couple more questions:

  1. How many rows and columns?
  2. Is it possible to reproduce the error by creating a dataframe from a numpy array with that shape and size?

@Khris777
Copy link

Khris777 commented Sep 19, 2017

@ccordoba12

Try this example, it reproduces the problem for me:

import pandas as pd
import numpy as np
nrow = 1000000
ncol = 50
test = np.ones((nrow,ncol),dtype=object)
df = pd.DataFrame(test)

Then enter commands like these into the console:

df.head()
df[df[1] == 1]
df[(df[1] == 1)&(df[4] == 1)]

You should pretty soon encounter a case when pressing enter will bring up another line and seemingly not executing the command.

The behaviour is erratic though, sometimes a command works, then it won't.

Adding the commands into a file and pressing F9 for that line always works, and sometimes after doing so entering a command manually will work again as well.

EDIT: It seems like dtype=object is a significant factor here. Using the same array with dtype=int makes it work well and to encounter some problematic behaviour (still way less than with dtype object) I need to set nrow = 10000000. But since I'm working with arrays/dataframes that have mostly strings in them (internally dtype object), the example case is fitting.

@ccordoba12
Copy link
Member

@Khris777, thanks a lot for the reproducible example, this is exactly what we need!

Since the cause of your problem is different from the one reported here, I opened issue #5280 to continue the discussion there.

@janjojose
Copy link

The problem is with the default editor for *.py files.
I had set it to Notepad++; so each time I execute the *.py file, it opens the instance of file in Notepad++ and returns a new Line.
Change the default editor for *.py file to default Python Application and it solves the problem.
Hope it helps.
:)

@maskerinus
Copy link

The problem still exists. Even now I am having the problem.
I press enter and instead of executing the command it give a new line in spyder.

@Mastiff37
Copy link

Just posting to say I am currently having this issue as well.

@nik-hil
Copy link

nik-hil commented May 4, 2019

@Mastiff37 it was visible in ipython 7.0. I updated the ipython with conda to 7.5. this issue is gone.

@sylasprime94
Copy link

Having this issue as well on macOS Mojave Version 10.14.6 Beta (18G48F)

Spyder 3.3.4
Python 3.7.0
IPython 7.5.0
conda 4.6.14

@ccordoba12
Copy link
Member

You need to use the Inline graphics backend instead of the Automatic one to fix this problem.

@endolith
Copy link

That's not a fix if we want to use the Automatic backend...

@ccordoba12
Copy link
Member

You can use the Tkinter backend instead.

@adrianschlatter
Copy link

Spyder 3.3.6 on MacOS seems to be completely broken. ENTER does not work. Opening bracket does not work. Very erratic: Often, it works after a kernel restart. But only for a few commands, then it's broken again.

@lingr7
Copy link

lingr7 commented May 20, 2020

Like here, with:Restart kernel for IPython console changes Enter behavior · Issue #2711 · spyder-ide/spyder

Spyder 4.1.3
Python 3.6.10 |Anaconda, Inc.| (default, May 7 2020, 19:46:08) [MSC v.1916 64 bit (AMD64)]
win10
IPython 7.13.0 -- An enhanced Interactive Python.

Copy the code from elsewhere and paste it into the Ipython Console to run it.
Sometimes the line continuation character is automatically added after pressing the Enter key, and sometimes it is run after pressing the Enter key.
In order to run, the adopted scheme is shift + enter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests