Python 3.9 script engine cannot load properly

Hello everyone,

I’m using grasshopper new python script component to import and use my custom python libraries inside grasshopper. At first launch of rhino everything goes smoothly and I can use my components freely, all good. But if I restart Rhino I keep getting this error :

It keeps happening and only restarting the computer allows for a new successful run. Do you have an idea of what I am missing ?

To develop a bit more on my envrionment, I’m developing my grasshopper plugin and launching Rhino8 via VS Studio 2022 in debug mode. I have installed manually my custom python libraries in the py39-rh8 folder via the pip exe packaged with rhino.
I also tried the behavior from the normal release laucnh of rhino 8, is allows for one run before encountering the same problem.

Hi Thomas, I assigned this Ehsan, do you have a log he can look at? Note that user file paths are in the log, if that is a concern for you please don’t post publically.

  • location of logs is in %HOMEPATH%\.rhinocode
  • if you can access the script editor run RhinoCodeLogs, save the logs into a text file

Hi Japhy,
Here is the last 2 logs referring the error.
Thanks for your help :slight_smile:

Info 04/03/2024 16:50:31 [RhinoCode] Language Registered: Plain Text 1.0 (rhinocode.builtin.text)
Info 04/03/2024 16:50:31 [RhinoCode] Language Registered: JSON 1.0 (rhinocode.builtin.json)
Info 04/03/2024 16:50:32 [RhinoCode] Language Loader Registered: mcneel.pythonnet.python@3.*
Info 04/03/2024 16:50:32 [RhinoCode] Language Loader Registered: mcneel.ironpython.python@2.*
Info 04/03/2024 16:50:32 [RhinoCode] Language Loader Registered: mcneel.roslyn.csharp@*.*
Info 04/03/2024 16:50:32 [RhinoCode] Language Loader Registered: mcneel.gh1.grasshopper@1.*
Info 04/03/2024 16:50:32 [RhinoCode] Language Loader Registered: mcneel.markdig.markdown@*.*
Info 04/03/2024 16:50:32 [RhinoCode] Storage Site Registered: File (mcneel.eto.file)
Info 04/03/2024 16:50:32 [RhinoCode] Storage Site Registered: Web (mcneel.eto.http)
Info 04/03/2024 16:50:32 [RhinoCode] Platform Registered: Rhinoceros 3D @ 8.4.24044.15001 (mcneel.rhino3d.rhino)
Info 04/03/2024 16:50:32 [RhinoCode] RhinoCode server starting on \\.\pipe\rhinocode_remotepipe_18988
Info 04/03/2024 16:50:32 [RhinoCode] Rhino3D Initialized on Windows - NETFramework
Info 03/04/2024 16:51:05 [RhinoCode] Using existing runtime
Info 03/04/2024 16:51:05 [RhinoCode] Creating python 3.9.10 runtime
Info 03/04/2024 16:51:05 [RhinoCode] Deploying python packages
Info 03/04/2024 16:51:05 [RhinoCode] Deploying package from "site-interop.zip"
Info 03/04/2024 16:51:05 [RhinoCode] Deploying package from "utils.zip"
Info 03/04/2024 16:51:05 [RhinoCode] Deploying package from "pylint-2.10.2-py3-none-any.whl"
Info 03/04/2024 16:51:05 [RhinoCode] Deploying package from "pyflakes-2.4.0-py2.py3-none-any.whl"
Info 03/04/2024 16:51:05 [RhinoCode] Deploying package from "pycodestyle-2.8.0-py2.py3-none-any.whl"
Info 03/04/2024 16:51:05 [RhinoCode] Deploying package from "jedi-0.18.0-py2.py3-none-any.whl"
Info 03/04/2024 16:51:05 [RhinoCode] Deploying package from "black-21.8b0-py3-none-any.whl"
Info 03/04/2024 16:51:05 [RhinoCode] Deploying package from "pywin32-302-cp39-cp39-win_amd64.whl"
Info 03/04/2024 16:51:05 [RhinoCode] Deploying package from "psutil-5.9.1-cp39-cp39-win_amd64.whl"
Info 03/04/2024 16:51:05 [RhinoCode] Saving python runtime configs
Info 03/04/2024 16:51:05 [RhinoCode] PYTHONHOME: \\?\C:\Users\Thomas.PITIOT\.rhinocode\py39-rh8
Info 03/04/2024 16:51:05 [RhinoCode] PYTHONPATH: 
Info 03/04/2024 16:51:05 [RhinoCode] Loading python runtime from C:\Users\Thomas.PITIOT\.rhinocode\py39-rh8\McNeel.Python39.Runtime.dll
Info 03/04/2024 16:51:05 [RhinoCode] Engine Type: Python.Runtime.RhinoCodePythonEngine
Error 03/04/2024 16:51:06 [RhinoCode] Error Initializing Python | Error loading python engine | Une exception a été levée par la cible d'un appel.
   à System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   à System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   à System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
   à System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   à System.Activator.CreateInstance(Type type, Object[] args)
   à Rhino.Runtime.Code.Languages.PythonNet.CPythonRuntime.LoadEngine(CPythonStartupSteps startup)
   à Rhino.Runtime.Code.Languages.PythonNet.CPythonRuntime.LoadEngine(CPythonStartupSteps startup)
   à Rhino.Runtime.Code.Languages.PythonNet.CPythonRuntime.<>c__DisplayClass98_0.<InitRuntime>b__0(Access access)
   à Rhino.Runtime.Code.Languages.PythonNet.CPython`1.Start()
Error 03/04/2024 16:51:06 [RhinoCode] [CPY001] Runtime failed to initialize (Python 3.9.10 (mcneel.pythonnet.python))
Error loading python engine | Une exception a été levée par la cible d'un appel.
   à System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   à System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   à System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
   à System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   à System.Activator.CreateInstance(Type type, Object[] args)
   à Rhino.Runtime.Code.Languages.PythonNet.CPythonRuntime.LoadEngine(CPythonStartupSteps startup)
   à Rhino.Runtime.Code.Languages.PythonNet.CPythonRuntime.LoadEngine(CPythonStartupSteps startup)
   à Rhino.Runtime.Code.Languages.PythonNet.CPythonRuntime.<>c__DisplayClass98_0.<InitRuntime>b__0(Access access)
   à Rhino.Runtime.Code.Languages.PythonNet.CPython`1.Start()
Info 03/04/2024 16:51:06 [RhinoCode] Added Python 3.9.10 (mcneel.pythonnet.python) search path: C:\Users\Thomas.PITIOT\AppData\Roaming\McNeel\Rhinoceros\8.0\scripts
Info 03/04/2024 16:51:06 [RhinoCode] Language Registered: Python 3.9.10 (mcneel.pythonnet.python)
Info 03/04/2024 16:51:06 [RhinoCode] Using existing runtime
Info 03/04/2024 16:51:06 [RhinoCode] Creating python 2.7.12 runtime
Info 03/04/2024 16:51:06 [RhinoCode] Added IronPython 2.7.12 (mcneel.ironpython.python) search path: C:\Users\Thomas.PITIOT\AppData\Roaming\McNeel\Rhinoceros\8.0\scripts
Info 03/04/2024 16:51:06 [RhinoCode] Language Registered: IronPython 2.7.12 (mcneel.ironpython.python)
Info 03/04/2024 16:51:07 [RhinoCode] Added C# 9.0 (mcneel.roslyn.csharp) search path: C:\Users\Thomas.PITIOT\AppData\Roaming\McNeel\Rhinoceros\8.0\scripts
Info 03/04/2024 16:51:07 [RhinoCode] Language Registered: C# 9.0 (mcneel.roslyn.csharp)
Info 03/04/2024 16:51:07 [RhinoCode] Language Registered: Grasshopper 1.0 (mcneel.gh1.grasshopper)
Info 03/04/2024 16:51:07 [RhinoCode] Language Registered: Markdown 0.30.4 (mcneel.markdig.markdown)
Info 04/03/2024 16:42:52 [RhinoCode] Language Registered: Plain Text 1.0 (rhinocode.builtin.text)
Info 04/03/2024 16:42:52 [RhinoCode] Language Registered: JSON 1.0 (rhinocode.builtin.json)
Info 04/03/2024 16:42:52 [RhinoCode] Language Loader Registered: mcneel.pythonnet.python@3.*
Info 04/03/2024 16:42:52 [RhinoCode] Language Loader Registered: mcneel.ironpython.python@2.*
Info 04/03/2024 16:42:52 [RhinoCode] Language Loader Registered: mcneel.roslyn.csharp@*.*
Info 04/03/2024 16:42:52 [RhinoCode] Language Loader Registered: mcneel.gh1.grasshopper@1.*
Info 04/03/2024 16:42:52 [RhinoCode] Language Loader Registered: mcneel.markdig.markdown@*.*
Info 04/03/2024 16:42:52 [RhinoCode] Storage Site Registered: File (mcneel.eto.file)
Info 04/03/2024 16:42:52 [RhinoCode] Storage Site Registered: Web (mcneel.eto.http)
Info 04/03/2024 16:42:52 [RhinoCode] Platform Registered: Rhinoceros 3D @ 8.4.24044.15001 (mcneel.rhino3d.rhino)
Info 04/03/2024 16:42:52 [RhinoCode] RhinoCode server starting on \\.\pipe\rhinocode_remotepipe_44292
Info 04/03/2024 16:42:52 [RhinoCode] Rhino3D Initialized on Windows - NETCoreApp
Info 03/04/2024 16:43:17 [RhinoCode] Using existing runtime
Info 03/04/2024 16:43:17 [RhinoCode] Creating python 3.9.10 runtime
Info 03/04/2024 16:43:17 [RhinoCode] Deploying python packages
Info 03/04/2024 16:43:17 [RhinoCode] Deploying package from "site-interop.zip"
Info 03/04/2024 16:43:17 [RhinoCode] Deploying package from "utils.zip"
Info 03/04/2024 16:43:17 [RhinoCode] Deploying package from "pylint-2.10.2-py3-none-any.whl"
Info 03/04/2024 16:43:17 [RhinoCode] Deploying package from "pyflakes-2.4.0-py2.py3-none-any.whl"
Info 03/04/2024 16:43:17 [RhinoCode] Deploying package from "pycodestyle-2.8.0-py2.py3-none-any.whl"
Info 03/04/2024 16:43:17 [RhinoCode] Deploying package from "jedi-0.18.0-py2.py3-none-any.whl"
Info 03/04/2024 16:43:17 [RhinoCode] Deploying package from "black-21.8b0-py3-none-any.whl"
Info 03/04/2024 16:43:17 [RhinoCode] Deploying package from "pywin32-302-cp39-cp39-win_amd64.whl"
Info 03/04/2024 16:43:17 [RhinoCode] Deploying package from "psutil-5.9.1-cp39-cp39-win_amd64.whl"
Info 03/04/2024 16:43:17 [RhinoCode] Saving python runtime configs
Info 03/04/2024 16:43:17 [RhinoCode] PYTHONHOME: \\?\C:\Users\Thomas.PITIOT\.rhinocode\py39-rh8
Info 03/04/2024 16:43:17 [RhinoCode] PYTHONPATH: 
Info 03/04/2024 16:43:17 [RhinoCode] Loading python runtime from C:\Users\Thomas.PITIOT\.rhinocode\py39-rh8\McNeel.Python39.Runtime.dll
Info 03/04/2024 16:43:17 [RhinoCode] Engine Type: Python.Runtime.RhinoCodePythonEngine
Error 03/04/2024 16:43:17 [RhinoCode] Error Initializing Python | Error loading python engine | Exception has been thrown by the target of an invocation.
   at System.Reflection.ConstructorInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
   at System.Activator.CreateInstance(Type type, Object[] args)
   at Rhino.Runtime.Code.Languages.PythonNet.CPythonRuntime.LoadEngine(CPythonStartupSteps startup)
   at Rhino.Runtime.Code.Languages.PythonNet.CPythonRuntime.LoadEngine(CPythonStartupSteps startup)
   at Rhino.Runtime.Code.Languages.PythonNet.CPythonRuntime.<>c__DisplayClass98_0.<InitRuntime>b__0(Access access)
   at Rhino.Runtime.Code.Languages.Runtime.Access.Run(String id, Action`1 task)
   at Rhino.Runtime.Code.Languages.PythonNet.CPythonRuntime.InitRuntime(CPythonStartupSteps startup)
   at Rhino.Runtime.Code.Languages.PythonNet.CPython`1.Start()
Error 03/04/2024 16:43:17 [RhinoCode] [CPY001] Runtime failed to initialize (Python 3.9.10 (mcneel.pythonnet.python))
Error loading python engine | Exception has been thrown by the target of an invocation.
   at System.Reflection.ConstructorInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
   at System.Reflection.RuntimeConstructorIn

I thought that the blank PYTHONPATH was the problem looking at the logs but the log when everything goes smootly also has blank PYTHONPATH. The dll just won’t load a second time :confused:

1 Like

@thomas.pitiot Would you mind testing Rhino 8.5 RC? We continuously improve how python is loading so I’m hoping this issue does not exists in 8.5 for you

Sure, where can I get my hands on it ?

Enable Service Release Candidates in Update and Statistics options:

1 Like

Has it been resolved in the end 8.6rc

It should be. I would appreciate if you can try 8.7 RC to be sure.

I do have similar, not yet the same problem with 8.7 (8.7.24101.10001):


Actually, the folder (without "\\?\") is accessible and (main) Rhino can read and write to it.

The result is that the ScriptEditor starts up but everything is greyed out:

Removing/renaming the .rhinocode folder in the home directory did the trick. At startup ScriptEditor sets up a clean python 3.9 and everything seem to work fine. Any ideas how to aviod this brute force approach in future?

@trademacher The runtime is trying to delete a folder named rhinoPython - site-envs that is NOT part of the default deployment. Is this something you have created?

Hmm…, good point. I remember that I tried to set an environment path in a script explicitly (“# env: /path/to/your/site-packages/”). Maybe this one pointed to this strange path above. Actually, I doubt that I created this path because I avoid path names with whitespaces and hyphens, but who knows…

Thanks.

Hey, sorry for the delayed answer, everything seems fine with Version 8 SR7
(8.7.24113.23001)

Edit : I lied … problem occured again today -_-

Here is my latest log of the failure with version 8 SR7 :

Info 04/25/2024 09:48:45 [RhinoCode] Language Registered: Plain Text 1.0 (rhinocode.builtin.text)
Info 04/25/2024 09:48:45 [RhinoCode] Language Registered: JSON 1.0 (rhinocode.builtin.json)
Info 04/25/2024 09:48:45 [RhinoCode] Storage Site Registered: Local Drive (mcneel.eto.file)
Info 04/25/2024 09:48:45 [RhinoCode] Storage Site Registered: Rhino Files (mcneel.rhinoFiles.file)
Info 04/25/2024 09:48:45 [RhinoCode] Storage Site Registered: Web (mcneel.eto.http)
Info 04/25/2024 09:48:45 [RhinoCode] Rhino3D Initialized on Windows - NETCoreApp
Info 04/25/2024 09:48:45 [RhinoCode] Platform Registered: Rhinoceros 3D @ 8.7.24113.23001 (mcneel.rhino3d.rhino)
Info 04/25/2024 09:48:45 [RhinoCode] Operating System: Microsoft Windows NT 10.0.22635.0
Info 04/25/2024 09:48:45 [RhinoCode] RhinoCode server starting on \\.\pipe\rhinocode_remotepipe_30768
Info 04/25/2024 09:48:53 [RhinoCode] Language Loader Registered: mcneel.pythonnet.python@3.*
Info 04/25/2024 09:48:53 [RhinoCode] Language Loader Registered: mcneel.ironpython.python@2.*
Info 04/25/2024 09:48:53 [RhinoCode] Language Loader Registered: mcneel.roslyn.csharp@9.*
Info 04/25/2024 09:48:53 [RhinoCode] Language Loader Registered: mcneel.gh1.grasshopper@1.*
Info 04/25/2024 09:48:53 [RhinoCode] Language Loader Registered: mcneel.markdig.markdown@0.*
Info 04/25/2024 09:48:53 [RhinoCode] Using existing runtime: CPython 3.9.10/42 (x64)
Info 04/25/2024 09:48:53 [RhinoCode] Initializing CPython 3.9.10/42 runtime
Info 04/25/2024 09:48:53 [RhinoCode] Deploying python packages
Info 04/25/2024 09:48:53 [RhinoCode] Deploying package from "site-interop.zip"
Info 04/25/2024 09:48:53 [RhinoCode] Deploying package from "utils.zip"
Info 04/25/2024 09:48:53 [RhinoCode] Deploying package from "pylint-2.10.2-py3-none-any.whl"
Info 04/25/2024 09:48:53 [RhinoCode] Deploying package from "pyflakes-2.4.0-py2.py3-none-any.whl"
Info 04/25/2024 09:48:53 [RhinoCode] Deploying package from "pycodestyle-2.8.0-py2.py3-none-any.whl"
Info 04/25/2024 09:48:53 [RhinoCode] Deploying package from "jedi-0.19.2-py2.py3-none-any.whl"
Info 04/25/2024 09:48:53 [RhinoCode] Deploying package from "black-21.8b0-py3-none-any.whl"
Info 04/25/2024 09:48:53 [RhinoCode] Deploying package from "pywin32-302-cp39-cp39-win_amd64.whl"
Info 04/25/2024 09:48:53 [RhinoCode] Deploying package from "psutil-5.9.1-cp39-cp39-win_amd64.whl"
Info 04/25/2024 09:48:53 [RhinoCode] Saving CPython runtime configs
Info 04/25/2024 09:48:53 [RhinoCode] PYTHONHOME: \\?\C:\Users\Thomas.PITIOT\.rhinocode\py39-rh8
Info 04/25/2024 09:48:53 [RhinoCode] PYTHONPATH: 
Info 04/25/2024 09:48:53 [RhinoCode] Loading CPython engine from C:\Users\Thomas.PITIOT\.rhinocode\py39-rh8\McNeel.Python39.Runtime.dll
Error 04/25/2024 09:48:54 [RhinoCode] Error Initializing Python | Error loading CPython engine | Exception has been thrown by the target of an invocation.
   at System.Reflection.ConstructorInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture)
   at System.Activator.CreateInstance(Type type, Object[] args)
   at Rhino.Runtime.Code.Languages.PythonNet.CPythonRuntime.LoadEngine(CPythonStartupSteps startup)
   at Rhino.Runtime.Code.Languages.PythonNet.CPythonRuntime.LoadEngine(CPythonStartupSteps startup)
   at Rhino.Runtime.Code.Languages.PythonNet.CPythonRuntime.<>c__DisplayClass105_0.<InitRuntime>b__0(Access access)
   at Rhino.Runtime.Code.Languages.Runtime.Access.Run(String id, Action`1 task)
   at Rhino.Runtime.Code.Languages.PythonNet.CPythonRuntime.InitRuntime(CPythonStartupSteps startup)
   at Rhino.Runtime.Code.Languages.PythonNet.CPython`1.Start()
Error 04/25/2024 09:48:54 [RhinoCode] [CPY001] Runtime failed to initialize (Python 3.9.10 (mcneel.pythonnet.python))
Error loading CPython engine | Exception has been thrown by the target of an invocation.

I have the same behavior as before in the end, one sucessful execution, if I restart Rhino I get the error on all my script components. I can run once in Debug to get one more run before having to restart the computer. Any idea on your side ?