现在我收到错误:应用程序中的服务器错误。无法导入已键入的名称 说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。异常详细信息:IronPython.Runtime.Exceptions.ImportException:无法导入名称类型的源错误:第 44 行:expr));第 45 行:第 46 行:script.Execute(scope); 第 48 行:返回 scope.GetVariable("result");
public static string PythonEvaluate(string expr)
{
var engine = Python.CreateEngine(); var paths = engine.GetSearchPaths();
paths.Add(@"C:\Python27\Lib\Site-Packages");
paths.Add(@"C:\sympy");
engine.SetSearchPaths(paths);
var scope = engine.CreateScope();
var script = engine.CreateScriptSourceFromString(string.Format(@"
import sys
sys.platform = "win32" // Default is cli
from sympy import *
n = Symbol('n')
value = {0}
import clr
from System import String
result = clr.Convert(value , String)",
expr));
script.Execute(scope);
return scope.GetVariable("result");
}
protected void Page_Load(object sender, EventArgs e)
{
var result = PythonEvaluate("limit((1 + 3/n)**n, n, oo)");
Label3.Text = result;
}