在 VS Code python 笔记本中将 autopep8 和 linting 添加到 jupyter

use*_*933 9 python visual-studio autopep8 visual-studio-code jupyter-notebook

问题

错误突出显示和自动格式化可以成为帮助人们创建出色笔记本的绝佳工具。我正在尝试更改 VS 代码上的设置,以允许我在 python 笔记本中自动格式化为 pep8。

此 Jupiter 笔记本页面上,我发现我必须在 VSCode 的设置 > 首选项中的 .json 文件中添加一些行才能执行此操作。我特别有兴趣将我的代码更改为 pep8 编码约定,并添加 linting 以突出显示错误。

  1. linting(错误突出显示)
  2. 自动格式化(autopep8)

我在 Ubuntu 18.04 上使用 VS Code。以下是我的尝试,导致错误“不支持或定义代码语言”。

试图

在 VS code 中安装 Python 扩展和 autopep8 扩展并运行后

pip3 install autopep8
Run Code Online (Sandbox Code Playgroud)

我收到错误消息并且无法使用 pep8。

在此输入图像描述

如果您知道如何在 VS Code 中为 Jupyter 笔记本设置高效的工作环境,我将非常感谢您的帮助

概括

如何设置:

  1. linting(错误突出显示)
  2. 自动格式化(autopep8)

在 python 笔记本的 VS 代码中。

编辑1:

我也尝试在命令面板中运行autopep8并收到错误

Command 'autopep8' resulted in an error (Running the contributed command: 'extension.sayHello' failed.)
Run Code Online (Sandbox Code Playgroud)

小智 6

Nbextensions 是笔记本扩展,仅在笔记本本身内工作。VS Code 不支持本机笔记本,因此这些扩展目前无法工作。他们计划将其添加到每个链接的未来版本中