spyder icon indicating copy to clipboard operation
spyder copied to clipboard

Randomly broken input function

Open TBSenseo opened this issue 2 years ago • 9 comments

Issue Report Checklist

  • [x] Searched the issues page for similar reports
  • [x] Read the relevant sections of the Spyder Troubleshooting Guide and followed its advice
  • [x] Reproduced the issue after updating with pip freeze | %{$_.split('==')[0]} | %{pip install --upgrade $_} in PowerShell in the Python distribution's Scripts folder
  • [ ] Could not reproduce inside jupyter qtconsole (if console-related)
  • [x] Could not reproduce inside python.exe .\InputProblem.py (if console-related)
  • [x] Could not reproduce inside ipython.exe .\InputProblem.py (if console-related)
  • [ ] Tried basic troubleshooting (if a bug/error)
    • [x] Restarted Spyder
    • [ ] Reset preferences with spyder --reset
    • [ ] Reinstalled the latest version of Anaconda
    • [ ] Tried the other applicable steps from the Troubleshooting Guide
  • [x] Completed the Problem Description, Steps to Reproduce and Version sections below

Problem Description

When I run a script that includes print statements and user input queries using the input function, the input query does not work as normal quite regularly. When it happens, it seems to skip printing the newline character before printing the text from the input function and instead prints it after the input query text. This results in that there is no newline character between the text from the last print statement and the text from the input query and the cursor for entering the input is one line after the input query.

What steps reproduce the problem?

Run a script with print and input statements from within Spyder, e. g. InputProblem.py

#!python3
# -*- coding: utf-8 -*-
"""
Created on 04/20/2022
"""

sInput = None
while sInput != '':
	sInput = input('Specify another input (Keep empty to exit): ')
	print(f'The input was "{sInput}".')

Run the script until the problem occurs.

What is the expected output? What do you see instead?

The expected output is that there is always a newline character between the text from the print statement and the text from the input statement and that the cursor is located at the end of the text from the input statement.

What I see: InputProblem

Versions

  • Spyder version: 5.3.0 None
  • Python version: 3.9.12 64-bit
  • Qt version: 5.15.2
  • PyQt5 version: 5.15.6
  • Operating System: Windows 10

I have the problem since upgrading Spyder to 5.3.0, but downgrading Spyder alone did not fix it. When I add a time.sleep(20) between the print and the input statement, then it works as intended, but I do not want to modify all scripts and libraries in the same way since the input function then still does not work as it is supposed to work.

Dependencies

No dependencies.

TBSenseo avatar Apr 20 '22 10:04 TBSenseo

Hi @TBSenseo thank you for the feedback! I was able to reproduce this. Not totally sure but maybe this has something to do with the fix done for #16504 and https://github.com/spyder-ide/spyder/pull/17559? I think that some changes where also done in QtConsole so most probably you will need to downgrade QtConsole too as a workaround.

We will try to fix this in a future release :+1:

dalthviz avatar Apr 20 '22 16:04 dalthviz

I encountered the same issue (after a fresh conda/anaconda install of a virtual environment with python 3.12). The reason for me seems to be qtconsole 5.3, in particular its new lack of the separator keyword, see:

Traceback (most recent call last):
  File "/Users/mx/opt/anaconda3/envs/env_python39/lib/python3.9/site-packages/qtconsole/base_frontend_mixin.py", line 138, in _dispatch
    handler(msg)
  File "/Users/mx/opt/anaconda3/envs/env_python39/lib/python3.9/site-packages/spyder/plugins/ipythonconsole/widgets/debugging.py", line 278, in _handle_input_request
    return super(DebuggingWidget, self)._handle_input_request(msg)
  File "/Users/mx/opt/anaconda3/envs/env_python39/lib/python3.9/site-packages/qtconsole/frontend_widget.py", line 512, in _handle_input_request
    self._readline(msg['content']['prompt'], callback=callback, password=msg['content']['password'])
  File "/Users/mx/opt/anaconda3/envs/env_python39/lib/python3.9/site-packages/qtconsole/console_widget.py", line 2422, in _readline
    self._show_prompt(prompt, newline=False, separator=False)
TypeError: _show_prompt() got an unexpected keyword argument 'separator'

Downgrading to qtconsole 5.2 solved this for now.

MNGuenther avatar Apr 29 '22 10:04 MNGuenther

I encountered the same issue (after a fresh conda/anaconda install of a virtual environment with python 3.12). The reason for me seems to be qtconsole 5.3, in particular its new lack of the separator keyword, see:

Traceback (most recent call last):
  File "/Users/mx/opt/anaconda3/envs/env_python39/lib/python3.9/site-packages/qtconsole/base_frontend_mixin.py", line 138, in _dispatch
    handler(msg)
  File "/Users/mx/opt/anaconda3/envs/env_python39/lib/python3.9/site-packages/spyder/plugins/ipythonconsole/widgets/debugging.py", line 278, in _handle_input_request
    return super(DebuggingWidget, self)._handle_input_request(msg)
  File "/Users/mx/opt/anaconda3/envs/env_python39/lib/python3.9/site-packages/qtconsole/frontend_widget.py", line 512, in _handle_input_request
    self._readline(msg['content']['prompt'], callback=callback, password=msg['content']['password'])
  File "/Users/mx/opt/anaconda3/envs/env_python39/lib/python3.9/site-packages/qtconsole/console_widget.py", line 2422, in _readline
    self._show_prompt(prompt, newline=False, separator=False)
TypeError: _show_prompt() got an unexpected keyword argument 'separator'

Downgrading to qtconsole 5.2 solved this for now.

how would you downgrade to qtconsole 5.2 using miniconda3

GBoulware avatar May 19 '22 03:05 GBoulware

@GBoulware, with this command:

conda install qtconsole=5.2

But that version is not compatible with Spyder 5.3.0

ccordoba12 avatar May 19 '22 03:05 ccordoba12

I am having this same issue. I have unstalled/reinstalled anaconda 5 times, set up a conda-forge environment for spyder, and tried just about every fix out there. Then I installed spyder standalone. I'm still having this issue. I also downgraded qtconsole to 5.2. Spyder is unusable with this issue. Is there any fix at all?

caedwynn avatar May 26 '22 12:05 caedwynn

Hey @caedwynn, sorry for the inconvenience. This broke when trying to fix another bug related to input that was open for years. We'll try to fix it in our next version (5.3.2), to be released at the beginning of July.

ccordoba12 avatar May 26 '22 14:05 ccordoba12

Hey everyone, please update to qtconsole 5.3.1 to get the fix for this problem. We'll add a dependency on that version in our next Spyder version (5.3.2) so that users don't have to manually do that. But for now, that's what you need to.

ccordoba12 avatar Jun 06 '22 16:06 ccordoba12

Hey everyone, please update to qtconsole 5.3.1 to get the fix for this problem. We'll add a dependency on that version in our next Spyder version (5.3.2) so that users don't have to manually do that. But for now, that's what you need to.

Thanks. I had not had the issue since I updated Spyder and then downgraded Jupyter.

TBSenseo avatar Jun 07 '22 16:06 TBSenseo

Great! Glad to know that Qtconsole version fixed the problem for you.

ccordoba12 avatar Jun 07 '22 17:06 ccordoba12