Execute Python script in C # out of IronPython

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.