How to give jupyter cell standard input in python?

PythonJupyterJupyter Notebook

Python Problem Overview


I am trying to run a program on a jupyter notebook that accepts user input, and I cannot figure out how to get it to read standard input. For example, if I run the code with shift-enter:

a = input()
print(a)

the cell indicates it is running, but does not accept input from me. How do I get it to accept input?

Python Solutions


Solution 1 - Python

Use the raw_input() (for Python 2) or input() (for Python 3) methods.

Example code:

a = raw_input()
print(a)

Example notebook:

Solution 2 - Python

I came across the same problem, using the input in jupyternotebook, it blocks the execution and it does not work until restarting the program, so I added a print () after each input and my program is working.

Solution 3 - Python

Probably you hit Shift-Enter a second time without completing the first input with Enter, so the kernel was always waiting until the first command completed, before executing it again. If you use in the menu

"Kernel", "Interrupt",

all active commands are stopped (including the second execution of the box) and the problem should be solved without restarting the computer (or the browser / the kernel).

Solution 4 - Python

You are doing it right, you ony have to restart the kernel (over the Run button)

Solution 5 - Python

Restarted my computer, and everything worked fine. No idea what happened...

Solution 6 - Python

use raw_input instead of input if you are using python 2 version. if u still getting same problem then,

click on kernel then "restart and run all" and try to run the code again. this will fix it.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlexView Question on Stackoverflow
Solution 1 - PythonRahul TripathiView Answer on Stackoverflow
Solution 2 - PythonAndrea LongariniView Answer on Stackoverflow
Solution 3 - PythonnaeschdyView Answer on Stackoverflow
Solution 4 - PythonSantiagoView Answer on Stackoverflow
Solution 5 - PythonAlexView Answer on Stackoverflow
Solution 6 - Pythonuser8403237View Answer on Stackoverflow