输入功能不适用于Vscode中的python [英] Input functionality is not working with python in Vscode
问题描述
说明:
我正在使用Vscode Studio进行python编码,已经安装了与python相关的所有扩展,并且我想使用Jupyter.我在导入包或运行代码方面没有遇到任何问题,但是当我尝试从用户那里获取输入时,会抛出一个错误,指出"StdinNotImplementedError:raw_input被调用,但是此前端不支持输入请求."我没有在控制台上找到它.
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.
[图像错误] https://i.stack.imgur.com/BDUC5.jpg
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.
已采取的步骤:
- 使用raw_input函数代替输入.
- 安装和卸载python和jupyter扩展.
- 检查了jupyter笔记本--version(5.7.4)和python -m ipykernel --version(7.2.0)的版本.
- 重新启动内核,但遇到相同的错误.
观察: 使用python集成终端执行代码时,该问题不可复制
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.
推荐答案
Ctrl + Shift + D
Ctrl + Shift + D
环境-> Python 这将在当前目录的.vscode目录中创建launch.json文件
Environment -> Python This creates launch.json file within a .vscode directory in the current directory
粘贴以下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"
}
]}
保存文件并在编辑器中打开python脚本 无需调试即可开始
Save the file and open python script in the editor Start without debugging
这篇关于输入功能不适用于Vscode中的python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!