简体   繁体   English

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

[英]Add autopep8 and linting to jupyter in VS code python notebook

Question问题

Error highlighting and autoformatting can be great tools to help one create great notebooks.错误突出显示和自动格式化是帮助人们创建出色笔记本的绝佳工具。 I am trying to change the settings on the VS code to allow me to autoformat to pep8 in my python notebooks.我正在尝试更改 VS 代码的设置,以允许我在 python 笔记本中自动格式化为 pep8。

On this page for Jupiter notebooks have found that I have to put some lines in my.json files in the settings>preference of VSCode in order to do this.Jupiter 笔记本的此页面上,我发现我必须在 VSCode 的设置>首选项中的 my.json 文件中添加一些行才能执行此操作。 I am particularly interested in changing my code to the pep8 coding convention and also adding linting in order to highlight errors.我对将我的代码更改为 pep8 编码约定并添加 linting 以突出显示错误特别感兴趣。

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

I am using VS Code on Ubuntu 18.04.我在 Ubuntu 18.04 上使用 VS Code。 Below is my attempt that led to an error "Code language not supported or defined".以下是我的尝试导致错误“不支持或定义代码语言”。

Attempt试图

After installing the Python extension and the autopep8 extension in VS code and running在 VS 代码中安装 Python 扩展和 autopep8 扩展并运行后

pip3 install autopep8

I got an error message and was unable to use pep8.我收到一条错误消息,无法使用 pep8。

在此处输入图像描述

If you may know how to set up an efficient working environment in VS Code for Jupyter notebooks I would really appreciate any assistance如果您知道如何在 VS Code 中为 Jupyter 笔记本设置高效的工作环境,我将非常感谢任何帮助

Summary概括

How to set up:如何设置:

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

in VS code for python notebooks.在 python 笔记本的 VS 代码中。

Edit 1:编辑1:

I also tried running autopep8 in the command palette and got the error我还尝试在命令面板中运行autopep8并得到错误

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

Nbextensions are notebook extensions and only work within the notebook itself. Nbextensions 是笔记本扩展,仅在笔记本本身内工作。 VS Code does not support native notebooks so these extensions won't work at the time. VS Code 不支持本机笔记本,因此这些扩展当时无法工作。 They are planning to add it in future releases per link他们计划在每个链接的未来版本中添加它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM