我正在写一些python代码,包括opencv。现在必须使用c添加一些UI和m,但是呼叫.py你知道吗
ı尝试使用进程调用我的.py文件
string python = @"C:\Windows.old\Users\giris\AppData\Local\Programs\Python\Python37-32\python.exe";
string myPythonApp = "C://Users//giris//Desktop//staj_proje_son//main.py";
string ogrencioptik = textBox2.Text;
string cevapkagidi = textBox1.Text;
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(python);
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.RedirectStandardOutput = true;
myProcessStartInfo.Arguments = myPythonApp + " " + ogrencioptik + " " + cevapkagidi;
Process myProcess = new Process();
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();
StreamReader myStreamReader = myProcess.StandardOutput;
string myString = myStreamReader.ReadLine();
myProcess.WaitForExit();
myProcess.Close();
Python文件必须工作正常,并且必须将结果写入.txt文件。你知道吗
错误如下:
File "C://Users//giris//Desktop//staj_proje_son//main.py", line 1, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
如果您将python添加到path,您可以在cmd上调用它(假设您在Windows上运行),而不是在python上调用process,就像在cmd上运行python脚本:“python/myscript.py文件“参数”
或者你可以试试Microsoft.Hosting.Scripting脚本用铁蟒。:)祝你好运
相关问题 更多 >
编程相关推荐