[Python] Pythonnet (.Net in Python): Failed to initialize Python.Runtime dll

Discussão em 'Python' iniciado por Stack, Março 10, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to to load a dll from Python. To be more exact, I have Python 3.9.18 bundled with ArcGIS Pro. Default environemnt doesn't have pythonnet installed and it doesn't allow to install new modules. So I had to clone the environment and then use ArcGIS's package manager to install pythonnet. So, usinig this cloned environment, I tried something like this in my script:

    import clr
    clr.AddReference("DHI.Mike.Install");


    This gave me an error, about not finding the specified file (i.e. Dhi.Mike.Install). I checked that it is present in GAC, at least if I check it from Visual Studio command line.

    I noticed, however, that when I print pythonnet.get_runtime_info() the version is null, so I thought - aha, surely pythonnet is not initialized properly. So I went like this:

    from pythonnet import load, get_runtime_info
    load("netfx")
    import clr


    On load("netfx") I get the following:

    File "C:\Users\<...>.py", line 14, in <module>
    load("netfx")
    File "C:\<...>\AppData\Local\ESRI\conda\envs\arcgispro-py3-additionals\Lib\site-packages\pythonnet\__init__.py", line 144, in load
    raise RuntimeError("Failed to initialize Python.Runtime.dll")
    RuntimeError: Failed to initialize Python.Runtime.dll


    I have read few threads about this specific error, but I haven't found an answer yet. Somebody said to unlock the dll, but I don't see such option. The script would have to be portable so setting some absolute paths is not viable for me (and I don't know if it is the problem). I'm not sure what my next steps in researching this should even be. Any advice?

    Cheers

    Continue reading...

Compartilhe esta Página