0

I have a Python virtual environment (venv) with several external libraries/packages installed, such as torch, gradio, and HuggingFace's transformers. I use the interpreter inside the venv to indicate VSCode of code coloring.

It works well with torch and gradio, but not transformers. It's just whited out (the image below).

VS Code coloring works well with torch and gradio, but not `transformers

Code linting and autocompleting still work well. As shown in the image below, VSCode correctly suggested the function signature and docstring for pipeline.

Code linting and autocompleting still work well

I am using the Dark+ color theme. And my guess is this cannot be fixed by changing the theme as I tried and it didn't help.

Why does it happen? And how to fix it? Thanks a lot!

Vu Nguyen
  • 52
  • 5
  • 1
    first find out the TextMate scopes of the white parts, if they are different from the greeny parts you can create an issue at the Python extension to update the TextMate grammar, what happens if you write the `import` without `()` (unusual syntax), maybe use 2 or more `import` lines (Python doesn't matter) – rioV8 Jun 21 '23 at 08:06
  • @rioV8 Both scopes are "source.python". I also tried splitting the imports but it didn't help. The other way around, thanks to this https://github.com/microsoft/pylance-release/issues/4374#issuecomment-1550011223. Explicitly importing from the exact modules addressed the problem. `from transformers.pipelines import pipeline` and `from transformers.models.speecht5 import SpeechT5ForTextToSpeech, SpeechT5HifiGan, SpeechT5Processor` Satisfyingly, both syntax highlighting and Pylance's unknown import symbol are solved. (Sorry for the multiple edits, I'm new on Stackoverflow as a user). – Vu Nguyen Jun 22 '23 at 03:06
  • then you have to look at the `__init__.py` file of the `transformers` module, it does some strange importing of the modules like `pipeline`, maybe pylance can't handle that method – rioV8 Jun 22 '23 at 03:39
  • @rioV8 You're right. Should do the imports explicitly so Pylance can work correctly. – Vu Nguyen Jun 22 '23 at 03:48

0 Answers0