This question has already been answered:
I have a script on python (with third-party libraries). I want to connect it to a ready C # project. - How can I do it?
This question has already been answered:
I have a script on python (with third-party libraries). I want to connect it to a ready C # project. - How can I do it?
A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .
For these purposes you will need DynamicLanguageRuntime (or DLR) and IronPython (implementation of the Python interpreter in C #).
If you are using Visual Studio, everything is quite simple - use NuGet, find the DynamicLanguageRuntime and IronPython packages in it, install them. After that, you can run Python scripts like this:
ScriptEngine engine = Python.CreateEngine(); //Просто указываете python код engine.Execute("print 'hello, world'");
If you want to run a script from a file, you can do it like this:
ScriptEngine engine = Python.CreateEngine(); engine.ExecuteFile("ваш_путь_до_скрипта/python_script.py");
More details and steps, you can read here.
Source: https://ru.stackoverflow.com/questions/979486/
All Articles