"the type initializer for Delegates threw an exception" - using Create Runtime #2106
-
Hi all I've tried following the documentation: https://bonsai-rx.org/python-scripting/?tabs=windows I've installed python (v3.12.8). I created an environment as instructed via Any ideas what I might be doing wrong? I'm running
Prior to this I attempted installing python via miniforge (and tried various versions of python) but couldn't get past this error. b.com/user-attachments/assets/c9d84b98-d760-48fa-8f20-69e9c3c8fa09" /> |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @vruetten , It's cool to see you are trying out the Bonsai - Python scripting package! In my experience, the “Delegate” error in Bonsai often means that Bonsai can’t locate or load the Python DLL correctly. This is frequently caused by issues in the system PATH or conflicts between multiple Python installations. Below are some steps I recommend to help get started: Check for existing Python pathsOpen a Command Prompt (or PowerShell) and type: where python This should list all instances of python.exe that your system sees. If there’s more than one, it's possible that this can create problems when Bonsai tries to load the DLL. Uninstall / remove conflicting Python installationsBonsai will always try to load the first Python installation found on the PATH. So, if you see multiple Python installations (e.g., from the Microsoft Store, Miniconda, Miniforge), it might be helpful to uninstall them so you have only one “clean” Python installation, or prioritize the clean installation by making sure it appears first in the system PATH. You should verify that the Python installation is correct by typing: where python
python --version
Installing a fresh copy of PythonIf you haven't already, download the “Windows installer (64-bit)” for the version you want from python.org/downloads/windows (I use python 3.10.12 but python 3.12.8 has been tested and also works). During installation, check the option to “Add python.exe to PATH” so that Bonsai can detect it correctly. It may also be useful to select the Test in BonsaiOnce you have your clean Python installation ready, you can test it in Bonsai first without using a virtual environment. For this, simply open Bonsai and create a new workflow. Add a Another important thing to note: Bonsai uses Python.NET under the hood, so the Python engine is tied to the Bonsai application process, rather than each individual workflow run. If Python fails to load on the first attempt, you may need to restart the Bonsai application entirely before making changes and trying again. An easy way to do this is to press the Hopefully these steps can help you resolve the “Delegates” error. If you keep seeing the error or have additional questions, let me know and we can troubleshoot further. Good luck, and I hope this helps! |
Beta Was this translation helpful? Give feedback.
Hi @vruetten ,
It's cool to see you are trying out the Bonsai - Python scripting package! In my experience, the “Delegate” error in Bonsai often means that Bonsai can’t locate or load the Python DLL correctly. This is frequently caused by issues in the system PATH or conflicts between multiple Python installations. Below are some steps I recommend to help get started:
Check for existing Python paths
Open a Command Prompt (or PowerShell) and type:
This should list all instances of python.exe that your system sees. If there’s more than one, it's possible that this can create problems when Bonsai tries to load the DLL.
Uninstall / remove conflicting Python installations
Bonsai w…