I’m developing a Python plugin that uses a specific external library. I have the following setup:
- I’m using Visual Studio Code as my IDE
- I have access to the stub files (
.pyi
) for the library I’m using - The library is not installed in my development environment, as it will be available in the runtime environment where my plugin will be executed
Currently, Visual Studio Code is showing error messages for objects from this library, marking them as unknown, even though they exist in the library.
Is there a config file where I can tell VS Code to search for the definition of the objects from the library in the directory of the stub files? If yes how can I edit them,
I tried to modifiy the settings. under .vscode in my project root. (You can do that in file, preferrence, setting)
According to https://code.visualstudio.com/docs/python/settings-reference , I have to ovewrite stubPath and set languageServer to Default or Pylance
{
"python.analysis.stubPath": "C:\Program Files\Stubs",
"python.languageServer": "Pylance",
}
But noting happends
I tried with other settings like “extapath” but it didn t work either
3
This solution works but this is not optimal
I can copy paste the .py in a directory in the project like that
root
+-- stub_directory
+-- mycode
it work but I have to write
import sub_directory.importedfile
instead of
import importedfile
I can copy paste all pyi files directly in the root but that make the project more difficulty to read.
A best solution would be to add a configuration file somewhere in the project that enable pylance (a visual studio extension ) to enable visual studio to access the pyi files
1