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

Add autopep8 and linting to jupyter in VS code python notebook

问题

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

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

  1. linting (error highlighting)
  2. autoformatting (autopep8)

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

尝试

在 VS 代码中安装 Python 扩展和 autopep8 扩展后 运行

pip3 install autopep8

我收到一条错误消息,无法使用 pep8。

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

总结

如何设置:

  1. linting (error highlighting)
  2. autoformatting (autopep8)

在 python 笔记本的 VS 代码中。

编辑 1:

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

Command 'autopep8' resulted in an error (Running the contributed command: 'extension.sayHello' failed.)

Nbextensions 是笔记本扩展,只能在笔记本本身内使用。 VS Code 不支持本机笔记本,因此这些扩展目前无法使用。他们计划根据 link

在未来的版本中添加它