Getting bpy intellisense in Visual Studio

Does anyone have any tips on getting intellisense autocompletion working in Visual Studio?

I’m loosely following the steps from https://youtu.be/mYrPqrFY7mA?t=3m3s trying to adapt it to Windows and Visual Studio

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.

Any idea what’s going wrong?

I’ve made some progress getting this working after finding the page https://wiki.blender.org/index.php/User:Ideasman42/BlenderAsPyModule

I followed these instructions to move the files to the correct places

copy bin\bpy.pyd C:\Python36\Lib\site-packages\
copy bin\*.dll C:\Python36\Lib\site-packages\
del C:\Python36\Lib\site-packages\python36.dll
xcopy /E bin\2.79 C:\Python36\

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.

1 Like

Thanks,

I found the script that generates the python stub files here: https://github.com/mutantbob/pycharm-blender

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

There is also

2 Likes

You can try using Jedi engine instead of Intellisense. It works much better but also it is slower

The nutti/fake-bpy-module solution works great!

I just had to:

  1. Download the zip: Releases · nutti/fake-bpy-module · GitHub
  2. Extract it somewhere.
  3. 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:
{
    "python.autoComplete.extraPaths": [
        "<path-to-extracted-modules-folder>"
    ]
}
3 Likes