c# 调用python 测试成功的方式 ,其实所有编译成cmd都可以这样调用,首先系统要安装了python,然后找到一个python.exe的路劲可能不一定是系统路径因为可能包含在工程中,也没关系
private bool StartTest(string pythonPyFileName, string arg )
{
bool state = true;
if (!File.Exists(pythonPyFileName))
{
throw new Exception("The file was not found.");
return false;
}
string sArguments = pythonPyFileName;
sArguments += " " + arg + " " + " -u";//Python文件的路径用“/”划分比较常见
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = Application.StartupPath + @"\pythonProject2\venv\Scripts\python.exe";//环境路径需要配置好
start.Arguments = sArguments;
start.UseShellExecute = false;