首页 > 解决方案 > 在 Ipython 中使用 Pylint (Jupyter-Notebook)

问题描述

我想在使用 Jupyter-Notebook 时运行 Pylint 或任何等效项。有没有办法以这种方式安装和运行 Pylint?

标签: pythonpython-3.xjupyter-notebookpylintflake8

解决方案


pycodestyle相当于pylintJupyter Notebook,它能够根据PEP8样式指南检查您的代码。

首先,您需要通过键入此命令来安装pycodestylejupyter notebook

!pip install pycodestyle pycodestyle_magic

在 jupyter notebook 的单元格中运行此命令。安装成功后,你必须像这样在 Jupyter Notebook 单元中加载魔法,

%load_ext pycodestyle_magic

然后,您必须pycodestyle在要根据PEP8标准调查代码的单元格中使用。

以下是一些示例,以便更清晰地理解,

%%pycodestyle
a=1

输出:pycodestyle会给你这个信息,

2:2: E225 missing whitespace around operator

另一个例子,

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

输出:

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

推荐阅读