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?

Reported as a duplicate by participants 0xdb , Andrew , AK , freim , Kir_Antipov May 9 at 0:00 .

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 .

    1 answer 1

    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.