Using VSCode with Houdini 19 and Python 3

Using VSCode with Houdini 19 and Python 3
Setup · Results · Some observations · PS
2022-07-07

Hello, this is a long-overdue update of my previous post. It was a nice workflow enhacement and I've got a positive feedback on that. But many things have changed (for better!) since then and here is again a quick guide for setting up VSCode for Python development in Houdini.

I am using the latest production-ready version: Houdini 19.0.657, which includes Python 3.7.13. Hopefully this workflow will be valid for a few future Houdini, Python and VSCode versions. I've tested it on both Linux and Windows operating systems.

So let's dive in.

   

Setup

Setup is actually quite simple. We can specify the hython executable as a Python interpreter for VSCode. Official VSCode docs cover it nicely here.

Press Ctrl + Shift + P for the command palette, select Python: Select Interpreter and Enter interpreter path... options. Locate the hython binary in the open dialog.

I could find it in /opt/hfs19.0.657/bin/hython on Linux and c:\Program Files\Side Effects Software\Houdini 19.0.657\bin\hython3.7.exe on Windows.

That's it.

You might see the following errors, but restarting VSCode seems to fix the issue.

   

Results

Let's see how VSCode can help us with suggestions. I should also mention that I am using Microsoft's Python and Pylance extensions.

Let's create a dummy Python file for testing things:

import hou def print_node_path(node: hou.Node) -> None: """Print node's path.""" print(f"{node.path()}") def length_of_two_added_vectors(a: hou.Vector3, b: hou.Vector3) -> hou.Vector3: """Return length of a sum of two vectors.""" sum_vec: hou.Vector3 = a + b return sum_vec.length()

Pressing Ctrl + Space at various positions shows us helpful suggestions.

   

Some observations

Note that I am using (and you should too) type hints. These are handy helpers for IDE, humans, type-checkers when working with dynamically typed languages, like Python. Those hints aren't checked at runtime, but they help with development experience and code reliability. Type checkers like mypy can use them for detecting type errors before your users find them.

Without them the IDE does not know my intention of what type I would pass into the function, like here.

We can see that when using type hints, IDE's description matches the content from Houdini docs for the Node.path() method, which is quite handy:

However, there's a room for improvement. Let's take a look at this case:

I've removed type hint for the sum_vec variable. Shouldn't it be clear that the result should be hou.Vector3? VSCode's suggestion however doesn't know sum_vec's type and therefore doesn't show any suggestion for its length() method.

However Houdini docs state that the type of the addition's result is hou.Vector3:

Let's take a look at the hou.Vector3.__add__() method's docstring:

This explains the behavior. The docstring has a correct type annotation hou.Vector3, which is used in the online docs. However method's return type is HOM_Vector3, a HDK's C++ class, which the IDE cannot interpret and therefore treats it as Any.

Though this is a only a minor issue, which will probably be addressed in a future Houdini version.

Anyway, I am really happy with the Python 2 to 3 transition and the effort that SideFX has put into documentation and seamless transition. Very impressive feat.

   

PS

Let's try replacing HOM_Vector3 with Vector3 in the hou.py file.

Indeed that helps :)