Issues using Pythonnet to embed Python Script within C#

Viewed 18

I'm trying to use the pythonnet nuget package to embed Python 3.6.5 (32-bit) on .Net 6.0 but it throws the following exceptions:

  • System.TypeInitializationException: 'The type initializer for 'Delegates' threw an exception.'

  • DllNotFoundException: Could not load python36.dll.

  • Win32Exception: %1 is not a valid Win32 application.

It worked previously on a 64 bit installation of python but due to some libraries I will be using I need to use a 32-bit installation.

The code that throws these exceptions is:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Python.Runtime; //Quantconnect.pythonnet V2.0.17


public class PyScripts
{
    public PyScripts()
    {

        Runtime.PythonDLL = "python36.dll";
        PythonEngine.Initialize();

    }
}

When I instantiate this class the exceptions are thrown.

1 Answers
Related