How to fix 'RuntimeError: input(): lost sys.stdin' error in python 3.7
Asked Answered
L

9

10

I am practicing some codes and seemingly out of nowhere i have got this error when I ran a very usual piece of code. The problem i am solving takes input, calculates something and gives an output.

I was running it on an online IDE (some coding contest site) and since it wasn't very good(no surprises there!) i decided to run it on the Pycharm Community Edition and then copy paste it over there. Instead of giving me an output, it showed this,

Traceback (most recent call last):
  File "D:\Software\lib\io.py", line 52, in <module>
  File "D:\practice\abc.py", line 1, in <module>
RuntimeError: input(): lost sys.stdin

Process finished with exit code -1073740791 (0xC0000409)

the code i tried to run was this,

tc = int(input())
while tc > 0:
    c = 0
    a = int(input())

    while a > 0:
        print(a % 2)
        if (a % 2 == 0):
            a = a // 2
            c += a
    print(c, "is c")

    tc -= 1

this may or may not be helpful, but i don't know what's wrong.

Levenson answered 10/8, 2019 at 16:27 Comment(2)
I have seen this happen if you run a python program that "hangs". You think it is done, dead, but it is hanging there holding a system resource. Then you run again and you can get that error. Killing of zombie python processes, or restarting computer, will usually disappear the problem for me.Viewing
I had this error raised when I added a breakpoint to some code in order to do debugging. It was caused by the joblib/parallel.py module.Cyzicus
B
4

The problem could relate to your code editor / Python window. The QGIS Python console, for example, doesn't have stdin or stdout, so you would get the 'RuntimeError: input(): lost sys.stdin' error if running your code there.

See this post: https://gis.stackexchange.com/questions/343250/error-when-using-input-pyqgis-runtimeerror-input-lost-sys-stdin-qgis-3

Breechcloth answered 13/1, 2021 at 0:57 Comment(0)
M
3

I was searching solution for same problem . I found this question, so I will leave the solution which worked for my problem to help the other people who has the same issue.

Instead of using input() command I've used sys.argv[1] with this command I provide input for my program from command line like mpirun -n 4 python -m deneme.py 1000000. In this case 1000000 is my input.

Mossman answered 1/11, 2019 at 22:1 Comment(0)
L
1

I moved it to another folder and it is working fine. Other files in the old folder used to work fine, now they don't. Is this an error relating to OS?

Levenson answered 10/8, 2019 at 18:41 Comment(0)
I
1

I ran into this problem randomly from inside a cygwin window for the 'twine' package. Restarting cygwin and doing exactly the same thing again fixed the problem. No idea what the underlying issue is, and 'turn it off and on again' seems like prosaic advice but... try turning it off and on again.

Implicatory answered 21/8, 2020 at 17:52 Comment(1)
Yes I had this issue with Python 3.10 and Git Bash but it worked with Powershell.Raspy
T
1

when you write input() in your code, use pyinstaller compiler the .py file, without -w args. here is the example command line:

pyinstaller -F demo.py

that works fo me

Tideway answered 31/3, 2023 at 8:46 Comment(1)
You can set console=True in your spec file. pyinstaller.org/en/stable/usage.html#cmdoption-cHyperdulia
P
0

I fixed the same error in Visual Studio "Python" by Project > Properties then unclicking the "Windows Application" checkbox

Pereyra answered 10/1, 2022 at 15:35 Comment(0)
R
0

I was having the same problem but it solved it when I changed the encoding to UTF-8.

Rabble answered 14/6, 2022 at 2:1 Comment(0)
M
0

This error appeared to me when I tried to convert it to .exe. This happened because I was using "--windowed" when I wanted to run it in a terminal

Memorial answered 18/10, 2023 at 18:11 Comment(1)
Welcome to Stack Overflow! Please convert this post into a comment when you get the right to do it :) As you probably are aware, this would not qualify as answer (stackoverflow.com/help/how-to-answer)Colbycolbye
D
-1

this might sound stupid but try closing your idle not directly from exit button but, like if you using windows close it from task manager and liekwise in other os. and try reopening it, even if it didn't worked, try restarting your pc, this really sounds basic and stupid but it really works(at least it worked for me, and also worked for a friend to whom i advised this)

Draggle answered 17/9, 2021 at 15:53 Comment(1)
This really should be a comment, not an answer.Cabinetmaker

© 2022 - 2024 — McMap. All rights reserved.