Plugin: Python3 shared libraries and Grasshopper components

Hi,

Is there an example open-source Grasshopper plugin that uses a shared Python3 library that I could look at?

I’ve read the “Creating Rhino/Grasshopper Script Plugins” guide (and several others), but cannot seem to load a shared Python3 library.

What I am doing:

  1. Opening ScriptEditor
  2. Importing a folder with the following structure:

asdf/
__init__.py
mylibrary.py

  1. Importing a GH definition with a Python3 Script component with code that starts with

import mylibrary (import asdf.mylibrary also doesn’t work)

The error I see is “Error getting GH_ScriptInstance instance” which disappears when I comment out the import line (and fails later with a more intelligible error when I try to use the library which wasn’t imported: “name mylibrary is not defined”).

Rhino Version:
Version 8 SR29
(8.29.26063.11001, 2026-03-04)
Commercial

Grasshopper Version: 1.0.0008

Any leads, workarounds, pointers are very welcome.

At the moment I can workaround the issue by installing the necessary packages through a custom pip package, but I’m wondering how to do this in a way that would allow me to distribute those packages together with the plugin, and not have to separately install them with pip.

Thank you!

Hi,

you could install your own modules as (editable) module. It essentially adds a path to the local Python currently in use. This would require some form of self-initialisation after installation. I would assume you can repeat this as often as you want.

See:

Alternatively you could provide “compiled” python modules (“pyc”) or local wheel packages. But it all ends up in adding a path to the python installation and “install” on init.

Generally speaking library management is one of the pains in Python. One of the reasons why I would not go for Python on distributed code if doable. Unless you depend on hardcore Python3 libraries its a good choice to build real shared libraries (dll, so, dylib) in the language of your choice (which might interop with CPython or C# code.

Thanks Tom. I have the pip approach working. The Rhino/Grasshopper Script Plugins guide makes it sound like embedding folders as packaged libraries is supported and this is what I would like to clarify. The example in that guide is for a C# folder. I am wondering if the same mechanism is intended to work with Python packages as well (and if not, I suppose the documentation could be updated to reflect that).