Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Pylint or other linters with Jupyter Notebooks?

Is it possible to have a linter inside of a Jupyter Notebook?

like image 528
magisterbrownie Avatar asked Oct 02 '19 18:10

magisterbrownie


People also ask

Can you use Pylint in Jupyter notebook?

NbQa is a tool that allows you to run any standard python linter on a Jupyter notebook. The following linters are currently accessible from this tool: pylint, black, auto flake, check-ast, doctest, flake8, mypy and yapf.

How do I run a linter in Python?

For that, go to Settings/Preferences, click Other Settings, and then Pylint. Enter the PATH environment variable there and you are good to go. Now, you are done! Every time you run a code now, you can use Pylint to look for refactoring, convention, and other little warning signs.

Can I use Jupyter notebook for deep learning?

Google Colab is a FREE Jupyter notebook environment provided by Google especially for Deep Learning tasks. It runs completely in the cloud and enables you to share your work, save to your google drive directly, and offers resources for computing power.


2 Answers

  • Yes it is possible
  • You can install pycodestyle for Jupyter Notebook which is similar to pylint. You can use the below commands from inside a Jupyter Notebook shell:
# install
!pip install pycodestyle pycodestyle_magic


# load
%load_ext pycodestyle_magic


# use
%%pycodestyle
def square_of_number(
     num1, num2, num3, 
     num4):
    return num1**2, num2**2, num3*

# Output
2:1: E302 expected 2 blank lines, found 0
3:23: W291 trailing whitespace

  • Check this question out for more details. My answer is inspired by the answers in the link.
  • Check out this question for more similar linters and solutions.
like image 170
Amit Yadav Avatar answered Oct 16 '22 16:10

Amit Yadav


Yes - you can run any standard Python code quality tool on a Jupyter Notebook using nbQA

e.g.:

pip install -U nbqa pylint
nbqa pylint notebook.ipynb

disclaimer: I"m the author of nbQA

like image 1
ignoring_gravity Avatar answered Oct 16 '22 17:10

ignoring_gravity