C# 安装程序ironpython:未找到模块

C# 安装程序ironpython:未找到模块,c#,python-3.x,ironpython,system-paths,C#,Python 3.x,Ironpython,System Paths,我第一次使用Ironpython将Python脚本导入C#。我得到错误“没有名为numpy的模块”,但我不知道为什么。我读到我必须将模块的路径添加到python脚本中。这是我的python脚本: import numpy as np import sys sys.path.append(r"C:\Users\abc\CSharp\PythonScriptExecution1\packages\IronPython.2.7.9\lib") sys.path.append(r"C:\Users\ab

我第一次使用Ironpython将Python脚本导入C#。我得到错误“没有名为numpy的模块”,但我不知道为什么。我读到我必须将模块的路径添加到python脚本中。这是我的python脚本:

import numpy as np
import sys
sys.path.append(r"C:\Users\abc\CSharp\PythonScriptExecution1\packages\IronPython.2.7.9\lib")
sys.path.append(r"C:\Users\abc\PycharmProjects\untitled3\venv\Lib")
sum = np.sum([0.5, 1.5])
print(sum)
第二个路径是Pycharm中用于python.exe的项目解释器的路径

我的C#代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PythonScriptExecution2
{
    class Program
    {
        static void Main(string[] args)
        {
            Microsoft.Scripting.Hosting.ScriptEngine pythonEngine =
                IronPython.Hosting.Python.CreateEngine();
            // We execute this script from Visual Studio 
            // so the program will be executed from bin\Debug or bin\Release
            Microsoft.Scripting.Hosting.ScriptSource pythonScript =
                pythonEngine.CreateScriptSourceFromFile("C:/Users/abc/PycharmProjects/untitled3/test.py");
            pythonScript.Execute();
        }
    }
}
在Pycharm中运行Python脚本工作正常,但将其导入C#会导致上述错误。有人能帮我设置正确的路径吗

编辑:如果它不起作用,有人知道用C#运行python脚本的其他方法吗?

使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Threading.Tasks;
命名空间PythonScriptExecution2
{
班级计划
{
静态void Main(字符串[]参数)
{
Microsoft.Scripting.Hosting.ScriptEngine eEngine=
IronPython.Hosting.Python.CreateEngine();
//我们从VisualStudio执行这个脚本
//因此程序将从bin\Debug或bin\Release执行
Microsoft.Scripting.Hosting.ScriptSource Python脚本=
ICollection searchpath=engine.getsearchpath();
添加(@“C:\Users\abc\CSharp\PythonScriptExecution1\packages\IronPython.2.7.9\lib”);
添加(@“C:\Users\abc\PycharmProjects\untitled3\venv\Lib”);
engine.SetSearchPath(搜索路径);
CreateScriptSourceFromFile(“C:/Users/abc/PycharmProjects/untitled3/test.py”);
pythonScript.Execute();
}
}
}

您需要下载适用于ironpython的numpy。->祝你好运,我不能让它工作。谢谢,但我也不能让它工作…很抱歉听到这个消息,我们找到的解决方案是在
进程中直接将脚本调用到python.exe,所以最后就像从cmd调用脚本一样。有一些变通方法可以传递参数并从process类接收输出。顺便说一句,在您尝试之前,Pythonnet为我们提供了相同的结果。它不起作用。。。我修改了您的代码,使其处于运行状态,但错误是相同的