我在VS 2015的C#.Net 3.5应用程序中使用IronPython。 我阅读了有关此主题的所有帖子,但仍然收到此错误。我的代码:
static void Main(string[] args)
{
var engine = Python.CreateEngine();
var searchPaths = engine.GetSearchPaths();
searchPaths.Add(@"C:\myProject\packages\DynamicLanguageRuntime.1.1.2");
searchPaths.Add(@"C:\myProject\packages\IronPython.2.7.7\lib");
searchPaths.Add(@"C:\myProject");
searchPaths.Add(@"C:\myProject\"where myfile.py exists");
engine.SetSearchPaths(searchPaths);
var mainfile = @"C:\myProject\myfile.py";
var scope = engine.CreateScope();
engine.CreateScriptSourceFromFile(mainfile).Execute(scope);
var result = scope.GetVariable("res");
// Console.WriteLine(result);
Console.ReadKey();
}
和myfile.py以:
开头import os
import csv
import unirest
.
.
res = "something"
有人知道会出现什么问题吗? 谢谢。
答案 0 :(得分:2)
我的问题已解决。我需要下载python 2.7.13,然后更改行:
searchPaths.Add(@"C:\myProject\packages\IronPython.2.7.7\lib");
到行:
searchPaths.Add(@"C:\Python27\Lib");