2
$\begingroup$

I use Visual Studio Code (VSCode) as a dev environment for Blender addons. I installed the ms-python.python extension, and enabled the language server for pylint linting.

But, it doesn't know about Blender's various built-in modules:

unresolved import 'bpy'

What's the best solution to this? It would be ideal if I can enable strict checking on bpy and friends. But I would also accept if the best answer is just to configure the linter to ignore certain unresolved imports.

$\endgroup$
1
3
$\begingroup$

Push Ctrl+Shift+P to open the command bar.

Paste ">Preferences: Open Settings (JSON)" (without the quotes) into it and press Enter.

In the text editor on the right side you need to paste in:

"python.analysis.disabled": ["unresolved-import", "use-before-def"],

(The whole line, do not forget the parenthesis in the beginning! It needs to be somewhere between the curly brackets)

You can also suppress linter warnings with:

"python.linting.pep8Args": ["--ignore=E501, E126"],

(However this line changes depending on your active line interpreter, which you can set with: ">Python: Select Linter", I opted for the PEP8 one, seems I am a little masochist... The E numbers in the end changes depending on the actual error messages you want to be gone.)

Last step would be to save the .json and you are good to go!

$\endgroup$
1
  • $\begingroup$ This did not work in VSC's latest version. the linter still gives the same error. Any follow up on a way to resolve it? $\endgroup$ – Iam KraZasHell Sep 26 '19 at 20:34
4
$\begingroup$

For this specific case you could try the Fake BPY module, which seems to be designed to solve this: https://github.com/nutti/fake-bpy-module

$\endgroup$
1
  • 1
    $\begingroup$ Can also build bpy as a python module. $\endgroup$ – batFINGER Dec 26 '19 at 13:09
0
$\begingroup$

Just disable "Python › Linting: Enabled" checkbox in VSCODE settings

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.