VTK 8.2 Python and VSCode

(Boris Basic) #1

Hi,

I am unable to get VTK Python autocompletion to work properly using VS Code.
I am using VTK Python 8.2 with VSCode 1.33 on Windows 10 64 bits.

Using import vtk, I get the following result:
image

My Python environment is actually a conda environment, with libs like VTK, PyQt or HDF5 installed. The later ones are working with Intellisense.

Code using VTK works perfectly though, only autocompletion features are not.

Any idea?

(Ben Boeckel) #2

The vtk package does dynamic loading of its components. I recommend using vtkmodules in 8.2. Completion should work there.

(Boris Basic) #3

Yes I saw that, thanks. But since the updated wiki examples are still using the old ‘import vtk’, I thought this was the proper way.

Edit: even using vtkmodules does not work properly. I am able to get the list of classes of a given module (eg vtkFiltersGeneral), but then, when instantiating an object and trying to use it, no class members are available.

1 Like
(Ben Boeckel) #4

Ah, we should update the wiki examples. @lorensen

Hmm. I wonder if we’re missing __all__ or something on the generated classes. However, I get completion in ipython, so maybe VSCode expects something different? @dgobbi

(David Gobbi) #5

Autocompletion is on my to-do list for VTK 9, I’ve done a bit of work on it but it’s still a ways off because I haven’t had much time to dedicate to VTK recently.

The most robust method for supporting autocompletion is to generate .pyi files as described in PEP 484, so that’s the approach I am taking, but I’m also re-vamping the docstring generation.

1 Like
(Boris Basic) #6

Ok I understand, thanks both of you for your quick response!

(Pablo Hernandez Cerdan) #7

I can reproduce exactly this, autocompletion works for imported classes, but not for instantiated objects (not in ipython either). What is missing? Any tweak/workaround?