首先,该Python代码在PyCharm和命令提示符中完美运行。因此,在我的Windows机器上安装了Cv2模块。
但是当我使用IronPython脚本引擎运行时,它失败了,如下所示:
IronPython.Runtime.Exceptions.ImportException: 没有名为cv2的模块
我按照以下步骤设置了IronPython引擎。请注意,site-packages
有一个cv2.pyd
文件。
var engine = Python.CreateEngine();
List<string> pathes = engine.GetSearchPaths().ToList();
pathes.AddRange(new[]
{
@"C:\Python27\Lib\", @"C:\Python27\Lib\site-packages\"
});
engine.SetSearchPaths(pathes);
dynamic py = engine.ExecuteFile("sample.py"); // <- Exception occurred here.
我猜 engine.Setup.FileExtensions
只有 .py
文件,所以无法识别 cv2.pyd
。但是,我很难弄清楚如何将 .pyd
添加到设置中。
或者,我错过了什么吗?