I’ve compiled Blender as a python module, and put the module in a virtual environment. VS seems to recognise that there’s a module called bpy, but doesn’t seem to find any of the stuff inside it.
After doing this I’m able to get autocompletion working great in the Python console in Visual Studio, but in actual code files it doesn’t find everything. I think the reason it’s not working has something to do with the note on that wiki page:
Unlike on *nix C:\Python36\2.79 is not in the site packages, this is because of a difference in how Windows finds the scripts path and should eventually be fixed.
It’s not clear where intellisense is looking for these things, but it doesn’t seem to be the same place as python running from the console.
I have setup vs_code autocomplete for bpy.xxx by these steps:
a)Get PYREFDEF from pitiwazu video description: https://www.youtube.com/watch?v=RuCqqy6gLwA
b)put bpy.py (and other definition files) to some folder eg.:
C:\Users<usr_name>\AppData\Roaming\Blender Foundation\Blender\2.79\pypredef{*.py files here}
c)Got to vscode settings (F1-> user settings-> :
Code:
“python.autoComplete.extraPaths”: [“C:/Users/’<usr_name>’/AppData/Roaming/Blender Foundation/Blender/2.79/pypredef”],
That is it, now autocomplete will work for bpy.xxx.
Looks like it’s generating bad Python in a couple of places, so the stub files aren’t perfect, but they are a big help.
Visual Studio has a different setup to VSCode, but putting them somewhere Visual Studio can find them seems to work. If I also include python files from 2.79\scripts\modules that gives even more autocomplete
Add the extracted folder’s path (ie. of the inner fake_bpy_modules_XXX) to your IDE’s list of Python-autocomplete sources. In VSCode, this means adding the following to your workspace’s settings.json file: