💡 Houdini Python Tips

💡 Houdini Python Tips

Thumbnail of Houdini Python Tips

Programming Resource for advanced python usage inside of Houdini.
Very relevant for advanced algorithms development and execution.

You can download the files with all the tips from here:

⬇️ Download example files

Installing python packages using pip 📦

Houdini comes with its own python environment that is independent of the system python. Out of the box it will at times lack some packages, giving you an error as seen below:

Thumbnail of Houdini Python Tips

To install a new python package using pip inside of houdini's python environment, you need to:

Step 1: Open a Houdini python shell:

Step 2: Type the following command and hit enter:

import pip

Step 3: Type the following command and hit enter:

pip.main(['install', 'package_name'])
Thats it! You should see a message telling you that the package was installed.

Thumbnail of Houdini Python Tips

Example: To install the `scipy` package, type the following command in the Houdini Python shell:

pip.main(['install', 'scipy'])

Test if the installtion worked by importing your package by writing the following code into a python node.

import scipy
print("If you see no errors, the import was successful!")

(If anything changes after updates and this solution no longer works, please email me so I can update the method. Yes I see the deprication warnings, but it is still the simplest solution.)

Using an IDE to write into python nodes 📝

When editing python nodes inside of Houdini, the coding environment lacks many quality of life features. Luckily, there is a way to just tell the python node to run code from a specific .py file that we can then edit from any IDE of your choice.

Step 1: Create a folder in your Houdini working directory ("HIP") where you will place your .py files. For example, you can create a file "working directory"/python/example_file.py.

Step 2: Create a Python node and insert the following code:

file = "example_file"
folder = "python"
exec(open(hou.getenv('HIP') + '/' + folder + '/' + file + '.py', 'r').read())

Step 3: When you edit your .py files in any IDE and save them, you will need to force houdini to recook the python node in order for it to execute the new version. A simple way to force that is to deactivate/activate the python node (the yellow bypass arrow) or to force a recook anywhere before the python node.

Thumbnail of Houdini Python Tips

Now you can enjoy all the benefits of your favorit IDE!