我的 Windows 10 机器上安装了 anaconda3。我想让 python 脚本运行并将结果返回给 C#。所以这是我在 C# 中的代码:
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = @"C:\Users\John\AppData\Local\Cotinum\anaconda3\python.exe";
start.Arguments = string.Format("{0}", @"C:\test.py", "test");
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
using(Process process = Process.Start(start))
using (StreamReader reader = process.StandardOutput)
{
string foo = reader.ReadToEnd();
TxtResultOutput.Text += foo;
}
蟒蛇代码
import pandas as pd
import sys
def test_func(f_name):
a = pd.read_excel(f_name)
return a
if __name__ == "__main__":
f_name = sys.argv[1]
test_func(f_name)
当我在 Visual Studio 的输出窗口中运行 C# 代码时。它显示错误:
文件“C:\Users\John\AppData\Local\Continuum\anaconda3\lib\site-package\pandas__init__.py”,第 19 行,
在模块中
“缺少必需的依赖项 {0}”.format(missing_dependencies))
ImportError:缺少必需的依赖项 ['numpy']
但是我不相信我错过了它,因为我可以从 anaconda3 提示窗口运行脚本。一定是在 Visual Studio/C# 环境中找不到路径。