【问题标题】:Input functionality is not working with python in Vscode输入功能不适用于 Vscode 中的 python
【发布时间】:2019-05-23 10:51:42
【问题描述】:

说明:

我正在使用 Vscode Studio 进行 python 编码,我已经安装了所有与 python 相关的扩展,我想使用 Jupyter。我在导入包或运行代码时没有遇到任何问题,但是当我尝试从用户那里获取输入时,它会抛出一个错误,指出“StdinNotImplementedError:调用了 raw_input,但是这个前端不支持输入请求。”我没有使用控制台找到。

[图像错误] 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.

采取的步骤:

  1. 使用 raw_input 函数代替 input。
  2. 安装和卸载 python 和 jupyter 扩展。
  3. 检查了 jupyter notebook --version (5.7.4) 和 python -m ipykernel --version (7.2.0) 的版本。
  4. 重新启动内核但遇到同样的错误。

观察: 使用python集成终端执行代码时,该问题不可复制

如果有我遗漏的设置或者这是一个错误,请告诉我。

【问题讨论】:

  • 请以正确的格式提问。
  • 这里是a similar question,可能会有所帮助。它适用于 java,但在这里不应该相关。
  • @Joakim Danielson,谢谢,但此问题仅在使用 jupyter 功能时出现在 vs code studio 中,并且仅在有人使用输入命令输入时才会出现。

标签: python-3.x visual-studio-code jupyter


【解决方案1】:

Ctrl + Shift + D

环境 -> Python 这会在当前目录的 .vscode 目录中创建 launch.json 文件

粘贴以下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 脚本 不调试就开始

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-17
    • 1970-01-01
    • 1970-01-01
    • 2014-08-30
    • 2015-11-27
    • 2019-12-09
    • 2017-04-05
    • 1970-01-01
    相关资源
    最近更新 更多