Shaz
Shaz

Reputation: 191

Input functionality is not working with python in Vscode

Description:

I'm using Vscode Studio for python coding, I've installed every extension related to python and I wanna use Jupyter. I'm experiencing no problem with importing packages or running code but when I try to grab the input from the user it throws me an error stating 'StdinNotImplementedError: raw_input was called, but this frontend does not support input requests.' which I don't find using the console.

[Image Error] https://i.sstatic.net/BDUC5.jpg

Error

StdinNotImplementedError                  Traceback (most recent call last)
 in 
      9 while 1:
     10     #ask for new item
---> 11     new_item=input("> ")
     12     #add new items to our list
     13     shopping_list.append(new_item)

~\AppData\Local\Programs\Python\Python37-32\lib\site-packages\ipykernel\kernelbase.py in raw_input(self, prompt)
    846         if not self._allow_stdin:
    847             raise StdinNotImplementedError(
--> 848                 "raw_input was called, but this frontend does not support input requests."
    849             )
    850         return self._input_request(str(prompt),

StdinNotImplementedError: raw_input was called, but this frontend does not support input requests.

Steps Taken:

  1. Use the raw_input function instead of input.
  2. Install and uninstall python and jupyter extension.
  3. Checked the version of jupyter notebook --version (5.7.4) and python -m ipykernel --version (7.2.0).
  4. Restarted kernel but encounter the same error.

Observation: The issue is not replicable when the code is executed with python integrated terminal

Please let me know if there is setting which I'm missing or is this a bug.

Upvotes: 3

Views: 10336

Answers (1)

loki
loki

Reputation: 972

Ctrl + Shift + D

Environment -> Python This creates launch.json file within a .vscode directory in the current directory

Paste the following json:

{
"version": "0.2.0",
"configurations": [
    {
        "name": "Python",
        "type": "python",
        "request": "launch",
        "stopOnEntry": true,
        "pythonPath": "${config.python.pythonPath}",
        "program": "${file}",
        "debugOptions": [
            "WaitOnAbnormalExit",
            "WaitOnNormalExit",
            "RedirectOutput"
        ],
        "console": "integratedTerminal"
    }
]}

Save the file and open python script in the editor Start without debugging

Upvotes: 2

Related Questions