Pylance "Invalid Character in token" for !pip commands

4.1k Views Asked by At

I am running Python 3.9.5 in interactive mode on VSCode. My first cell looks like this:

pip commands giving errors

The error is

Invalid character in token "" Pylance

.
The code still runs fine when I press Run Cell.

How can I make Pylance ignore these commands or get rid of the errors somehow?

Extensions:

  • Pylance 1021.5.1
  • Python 2021.5.829140558
  • Jupyter 2021.5.745244803

OS: Windows 10

1

There are 1 best solutions below

1
On BEST ANSWER

This will be reported as a warning:

!pip install numpy

This will force Pylance to ignore warnings in that line

!pip install numpy # type: ignore

enter image description here

This is ok if you only have a few lines, but ideally, I would like to have a single comment/annotation to disable the linter and then another comment/annotation to re-enable it, but I can't figure out how to do that, perhaps something like:

# 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