Skip to content

Running script with CLR a second time gives "RuntimeError: Failed to initialize Python.Runtime.dll" #2099

@szhuge-ci

Description

@szhuge-ci

Environment

  • Pythonnet version: 3.0.1
  • Python version: 3.10.9
  • Operating System: Windows 11
  • .NET Runtime: 4.8

Details

  • Describe what you were trying to get done.

I'm using the Spyder IDE with Conda. When I run a Python script to import CLR and add references, the first time it works. However, if I re-run, then the second time it fails with an error, and I have to restart my Spyder IDE for it to work again.

Running this once, works fine. Run it a second time, get an error

import clr

clr.AddReference('System.Linq')
clr.AddReference('System.Collections')
  • If there was a crash, please include the traceback here.
Reloaded modules: CLR, clr
Traceback (most recent call last):

  File ~\miniconda3\envs\spyder-env\lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
    exec(code, globals, locals)

  File c:\users\...\test.py:2
    import clr

  File ~\miniconda3\envs\spyder-env\lib\site-packages\clr.py:6
    load()

  File ~\miniconda3\envs\spyder-env\lib\site-packages\pythonnet\__init__.py:144 in load
    raise RuntimeError("Failed to initialize Python.Runtime.dll")

RuntimeError: Failed to initialize Python.Runtime.dll


Failed to initialize pythonnet: System.InvalidOperationException: This property must be set before runtime is initialized
   at Python.Runtime.Runtime.set_PythonDLL(String value)
   at Python.Runtime.Loader.Initialize(IntPtr data, Int32 size)
   at Python.Runtime.Runtime.set_PythonDLL(String value)
   at Python.Runtime.Loader.Initialize(IntPtr data, Int32 size)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions