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

4

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.

python
python-3.x
file-io
pycharm
user-input
asked on Stack Overflow Aug 10, 2019 by mach3

4 Answers

2

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.

answered on Stack Overflow Nov 1, 2019 by demirbilek
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?

answered on Stack Overflow Aug 10, 2019 by mach3
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.

answered on Stack Overflow Aug 21, 2020 by Lucian
0

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

answered on Stack Overflow Jan 13, 2021 by user7587050

User contributions licensed under CC BY-SA 3.0