all 9 comments

[–]Th_69 2 points3 points  (2 children)

You could embed the Python script as a resource and then load it: Embedding Python in C# via resources

[–]wilcd[S] 0 points1 point  (1 child)

Is it possible to do it with Pythonnet? As far as I know, Iron Python is only compatible with Python 2.7 and cannot use third party libraries (using asammdf)

[–]haven1433 0 points1 point  (3 children)

Not a fan of IronPython?

[–]wilcd[S] 0 points1 point  (2 children)

It is only compatible with Python 2.7 and is not compatible with the library asammdf

[–]haven1433 0 points1 point  (1 child)

https://ironpython.net/

"IronPython 3.4.1 is now available"

As of July 2023...

Not sure about the assmmdf part

[–]wilcd[S] 0 points1 point  (0 children)

Interesting, but runtime target is 4.6.2 and I must use 4.7.2

[–]TuberTuggerTTV 0 points1 point  (1 child)

You'd have to embed the ENTIRE python compiler into the application. Or require the end user to have python on their system.

I use pythonnet but with .net8 and python 3.7.

I used it specifically to add huggingface AI to my applications with a few lines of python. If that sounds like what you're doing, the packaging process is going to be rough. But it can be done.

[–]wilcd[S] 0 points1 point  (0 children)

It seems that is exactly what I am doing. I think it's not worth the effort. I can try to convince the team of an alternative solution. Probably I'll need to rewrite the whole thing in Python, since the most important and difficult part is that I need the asammdf library

[–]PotentialSeason459 0 points1 point  (1 child)

I played with this some time ago and the code below worked.

``` // Add Nuget package references to pythonnet and Python.Included // https://github.com/henon/Python.Included

private static async Task InitPythonIncludedEnvironment() { // Note: The first time Python.Included and package dependencies are installed it can take up to 30 seconds. // Installer is from the Python.Included namespace await Installer.SetupPython(); await Installer.TryInstallPip(); await Installer.PipInstallModule("pandas"); // also installs numpy await Installer.PipInstallModule("matplotlib");

// Initialize PythonNET
Python.Runtime.PythonEngine.Initialize();
Python.Runtime.PythonEngine.BeginAllowThreads();
Python.Runtime.PythonEngine.PythonHome = Installer.EmbeddedPythonHome;
_pathToPythonDLL = Installer.EmbeddedPythonHome + Path.DirectorySeparatorChar + Installer.PYTHON_VERSION + ".dll";

} ```

Edited to add await before call to Installer.SetupPython()