在visual studio中执行python文件时出错 [英] Error with python file execution in visual studio

查看:603
本文介绍了在visual studio中执行python文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的网站中添加python脚本,我正在使用它进行串行通信,这样做我正在使用ironpython ...

以下是我的网页的Codebehind文件: -



使用System.Collections.Generic;

使用System.Linq;

使用System.Web ;

使用System.Web.UI;

使用System.Web.UI.WebControls;

使用IronPython.Hosting;

使用Microsoft.Scripting.Hosting;

使用Microsoft.Scripting;

使用IronPython.Runtime;





公共部分类_Default:System.Web.UI.Page

{



静态ScriptEngine engine = Python.CreateEngine();

ScriptScope pyScope = engine.CreateScope();



protected void Page_Load(object sender,EventArgs e )

{



}





protected void Button1_Click(对象发送者,EventAr gs e)

{

试试

{



ScriptEngine pyEngine = Python .CreateEngine();

pyEngine.ExecuteFile(@D:\ project \ App_8th Sem \FinalDesign v0.3 \ scan.py); //错误在这里

}



catch(例外eo)

{

Label1.Text =err ==+ eo;

}

}

}



Scan.py文件:==

导入序列号

打印'你好......'



所以当我点击按钮时它会给我一个python运行时异常,如下所示: -



IronPython.Runtime.Exceptions。 ImportException:Microsoft.Scripting.Interpreter.Interpreter.Run上的Microsoft.Scripting.Interpreter.FuncCallInstruction`2.Run(InterpretedFrame框架)中的Microsoft.Scripting.Runtime.LightExceptions.CheckAndThrow(Object value)中没有名为serial的模块(InterpretedF位于IronPython.Compiler.PythonScriptCode.Run(范围范围)的IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)的Microsoft.Scripting.Interpreter.LightLambda.Run2 [T0,T1,TRet](T0 arg0,T1 arg1)处的rame框架) )位于Microsoft.Scripting.Hosting.ScriptSource.Execute的Microsoft.Scripting.SourceUnit.Execute(作用域范围,ErrorSink errorSink)上的IronPython.Compiler.RuntimeScriptCode.Run(作用域范围)中的IronPython.Compiler.RuntimeScriptCode.InvokeTarget(作用域范围) (ScriptScope范围)位于_Default.Button1_Click(对象发件人,EventArgs e)的Microsoft.Scripting.Hosting.ScriptEngine.ExecuteFile(字符串路径)中d:\ project @\\App_8th Sem \ FinalDesign v0.3\admDefault.aspx .cs:37行







我还在我的电脑上安装了pyserial ..



所以我错过了某种参考dll或者什么?

I'm adding python script in my website which i'm using it for serial communication and to do so i'm using ironpython...
Following is the Codebehind file of my webpage:--

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
using Microsoft.Scripting;
using IronPython.Runtime;


public partial class _Default : System.Web.UI.Page
{

static ScriptEngine engine = Python.CreateEngine();
ScriptScope pyScope = engine.CreateScope();

protected void Page_Load(object sender, EventArgs e)
{

}


protected void Button1_Click(object sender, EventArgs e)
{
try
{

ScriptEngine pyEngine = Python.CreateEngine();
pyEngine.ExecuteFile(@"D:\project\App_8th Sem\FinalDesign v0.3\scan.py");//error here
}

catch (Exception eo)
{
Label1.Text = "err ==" + eo;
}
}
}

Scan.py file:==
import serial
print 'hello... '

so when i click on button it gives me python runtime exception as below :--
"
IronPython.Runtime.Exceptions.ImportException: No module named serial at Microsoft.Scripting.Runtime.LightExceptions.CheckAndThrow(Object value) at Microsoft.Scripting.Interpreter.FuncCallInstruction`2.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame) at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1) at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx) at IronPython.Compiler.PythonScriptCode.Run(Scope scope) at IronPython.Compiler.RuntimeScriptCode.InvokeTarget(Scope scope) at IronPython.Compiler.RuntimeScriptCode.Run(Scope scope) at Microsoft.Scripting.SourceUnit.Execute(Scope scope, ErrorSink errorSink) at Microsoft.Scripting.Hosting.ScriptSource.Execute(ScriptScope scope) at Microsoft.Scripting.Hosting.ScriptEngine.ExecuteFile(String path) at _Default.Button1_Click(Object sender, EventArgs e) in d:\project\App_8th Sem\FinalDesign v0.3\admDefault.aspx.cs:line 37
"


and i also installed pyserial on my pc..

so am i missing some kind of reference dll or what??

推荐答案

这篇关于在visual studio中执行python文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆