Pylance import errors for built-in modules when developing python add-ons in VScode

Hello,

I’m working on an add-on in VScode, using a Blender VScode extension.
Pylance is showing import errors (reportMissingImports) on built-in modules:
reportMissingImport

As far as I understand, Blender executable contains a python interpreter, which has all these built-in modules loaded during blender build (or does it do it at runtime?), so this error is expected because the interpreter VScode uses won’t have these modules (the interpreter I’m using for VScode/Pylance is the one in the blender build files).

What’s the standard way to deal with this issue? When extending the python interpreter, blender’s just using compiled .o files of C modules, I presume. Can I just manually extend my own interpreter (the one VScode uses) using these files as well (by building blender and then saving these files, or are they already there in build_linux folder)? Or is there an easier/better way?

Any suggestion would be appreciated! :slight_smile:

1 Like

Try this:

It’s also great because it allows you to use autocompletion for Blender properties.

1 Like

Thanks @Strike_Digital !

On a related note, I have another question. Tutorials often do something like

class ExampleAddonPreferences(AddonPreferences):
...
    def draw(self, context):
        layout = self.layout

Where does self.layout come from? As far as I see, class AddonPreferences doesn’t have it, and it inherits from bpy_struct which doesn’t have it either, and bpy_struct doesn’t seem to inherit from anything…
I’m getting

If anyone has any ideas, I’d be thankful!

Why not just use the system Python? Then any extras that you install systemwide (e.g. Numpy) become automatically available within Blender.