Search code examples
pythonvisual-studiovisual-studio-codejupyter-notebookautopep8

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.

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. I am particularly interested in changing my code to the pep8 coding convention and also adding linting in order to highlight errors.

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

I am using VS Code on Ubuntu 18.04. 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

pip3 install autopep8

I got an error message and was unable to use pep8.

enter image description here

If you may know how to set up an efficient working environment in VS Code for Jupyter notebooks I would really appreciate any assistance

Summary

How to set up:

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

in VS code for python notebooks.

Edit 1:

I also tried running autopep8 in the command palette and got the error

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

Solution

  • Nbextensions are notebook extensions and only work within the notebook itself. VS Code does not support native notebooks so these extensions won't work at the time. They are planning to add it in future releases per link