Is it troublesome to install IronPython to the client in addition to installing the. NET Framework?
All of this is weak, let me introduce a way to do Python script in C # without installing IronPython simply by introducing a few IronPython DLLs.
1: Introduction of several DLLs in IronPython
2: Enter IronPython lib folder, the contents of Lib package into a zip, the name can be either. Pack it up and put it under the C # project.
I put it in the same directory as the py file.
3: A critical step to execute the next code when the program initializes
ScriptEngine engine = Python.createengine (); Scriptscope scope = engine. Createscope (); Scriptsource Source = engine. Createscriptsourcefromstring ( @ "import sys" "\ n" @ "Sys.path.append (" ". \scripts\pythonlib.zip" ")" \ n " @ "Sys.path.append (" ". \scripts" ")" \ n "); Source. Execute (scope);
Add the zip file to the Python library path. This will ensure that the Py script can correctly search the location of the Python library.
4: Enjoy the convenience of scripting language. Installing a program for someone else doesn't have to install a nasty IronPython environment.
Execute Python script in C # out of IronPython