!pip 命令的 Pylance“令牌中的无效字符”

问题描述

我在 VSCode 上以交互模式运行 Python 3.9.5。我的第一个单元格看起来像这样:

pip commands giving errors

错误

令牌 "" Pylance 中的无效字符

.
当我按下 Run Cell 时,代码仍然运行良好。

如何让 Pylance 忽略这些命令或以某种方式摆脱错误

扩展:

  • Pylance 1021.5.1
  • Python 2021.5.829140558
  • Jupyter 2021.5.745244803

操作系统:Windows 10

解决方法

这将被报告为警告:

!pip install numpy

这将强制 Pylance 忽略该行中的警告

!pip install numpy # type: ignore

enter image description here

如果你只有几行,这没问题,但理想情况下,我想要一个评论/注释来禁用 linter,然后另一个评论/注释来重新启用它,但我想不通如何做到这一点,也许是这样的:

# type: ignore on      <<<<<<<<<< NOTE: THIS DOES NOT WORK,I JUST WISH IT DID
!pip install numpy
!pip install matplotlib
!pip install pandas
# type: ignore off     <<<<<<<<<< NOTE: THIS DOES NOT WORK,I JUST WISH IT DID

,

尝试将 pip 更改为 pip3,因为来自 python3 的版本显示错误