如何在C#中调用Python脚本

1,C#中调用蟒脚本,一是通过IronPython的的直接运行蟒脚本(目前还不能不知道如何在Python中的中加第三方包)

2,通过的英文调用过程类启动电脑上的python.exe,运行蟒脚本。

如果不含第三方库,可以尝试两种方法的代码:

1. Process myProcess = new Process();
            myProcess.StartInfo.UseShellExecute = false;
            myProcess.StartInfo.FileName =“test_vs.exe”;
            myProcess.StartInfo.CreateNoWindow = true;

            myProcess.Start();

2.           dymamicPY = pyEngine.ExecuteFile(@ “test_vs.py”); //读取脚本文件
            string DD = py.dot68_coordinate(textBox1.Lines); //调用脚本文件中对应的函数
            textBox2.Text + = DD +“\ r \ n”;

第一种还没搞清楚,先介绍第二种

1.生成Python.exe

关于蟒蛇打包成EXE的一点经验之谈

PIP  安装 pyinstaller
pyinstaller  yourprogram 。PY

pyinstaller3的使用方法

        只生成一个exe文件的方法 D:\ test> pyinstaller --onefile test_vs.py或D:\ test> pyinstaller -F test_vs.py

打包过程遇到第一个问题:

file“f:\ programs \ anaconda3 \ lib \ site-packages \ PyInstaller \ compat.py”,第378行,在exec_command
    out = out.decode(encoding)
UnicodeDecodeError:'utf-8'编解码器无法解码字节0xce位置119:无效的连续字节

解决方案
out = out.decode(encoding, errors='ignore')

遇到第二个问题

RecursionError:超过最大递归深度(不知道如何解决)

跨语言和跨编译器的那些坑(CPython vs IronPython)看了让人崩溃

       果断换方向--PyQt编辑窗口窗口?????

猜你喜欢

转载自blog.csdn.net/lixiaoguai2017/article/details/80277746