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!

4
  • 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) Commented Jun 21, 2023 at 8: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 github.com/microsoft/pylance-release/issues/…. 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). Commented Jun 22, 2023 at 3: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 Commented Jun 22, 2023 at 3:39
  • @rioV8 You're right. Should do the imports explicitly so Pylance can work correctly. Commented Jun 22, 2023 at 3:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.