pythonvisual-studio-codepython-interactivepylance

Pylance "Invalid Character in token" for !pip commands


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:

OS: Windows 10


Solution

  • 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