铁python没有任何例外。 Microsoft.scripting.syntaxerrorexception:意外的令牌' from'
每次运行Iron Python脚本时,我都会遇到错误。我正在使用Windows 11 Ironpython 2.7.12和Python 3.10。这是我遇到的错误,
Unhandled exception. Microsoft.Scripting.SyntaxErrorException: unexpected token 'from'
at IronPython.Runtime.ThrowingErrorSink.Add(SourceUnit sourceUnit, String message, SourceSpan span, Int32 errorCode, Severity severity)
at IronPython.Compiler.Parser.ReportSyntaxError(Int32 start, Int32 end, String message, Int32 errorCode)
at IronPython.Compiler.Parser.ReportSyntaxError(Token t, IndexSpan span, Int32 errorCode, Boolean allowIncomplete)
at IronPython.Compiler.Parser.ParsePrimary()
at IronPython.Compiler.Parser.ParsePower()
at IronPython.Compiler.Parser.ParseFactor()
at IronPython.Compiler.Parser.ParseExpr(Int32 precedence)
at IronPython.Compiler.Parser.ParseComparison()
at IronPython.Compiler.Parser.ParseNotTest()
at IronPython.Compiler.Parser.ParseAndTest()
at IronPython.Compiler.Parser.ParseOrTest()
at IronPython.Compiler.Parser.ParseExpression()
at IronPython.Compiler.Parser.ParseExpressionList(Boolean& trailingComma)
at IronPython.Compiler.Parser.ParseYieldExpression()
at IronPython.Compiler.Parser.ParseYieldStmt()
at IronPython.Compiler.Parser.ParseSmallStmt()
at IronPython.Compiler.Parser.ParseSimpleStmt()
at IronPython.Compiler.Parser.ParseStmt()
at IronPython.Compiler.Parser.ParseSuite()
at IronPython.Compiler.Parser.ParseIfStmtTest()
at IronPython.Compiler.Parser.ParseIfStmt()
at IronPython.Compiler.Parser.ParseStmt()
at IronPython.Compiler.Parser.ParseSuite()
at IronPython.Compiler.Parser.ParseLoopSuite()
at IronPython.Compiler.Parser.ParseForStmt()
at IronPython.Compiler.Parser.ParseStmt()
at IronPython.Compiler.Parser.ParseSuite()
at IronPython.Compiler.Parser.ParseIfStmtTest()
at IronPython.Compiler.Parser.ParseIfStmt()
at IronPython.Compiler.Parser.ParseStmt()
at IronPython.Compiler.Parser.ParseSuite()
at IronPython.Compiler.Parser.ParseClassOrFuncBody()
at IronPython.Compiler.Parser.ParseFuncDef()
at IronPython.Compiler.Parser.ParseStmt()
at IronPython.Compiler.Parser.ParseFileWorker(Boolean makeModule, Boolean returnValue)
at IronPython.Compiler.Parser.ParseFile(Boolean makeModule, Boolean returnValue)
at IronPython.Runtime.PythonContext.ParseAndBindAst(CompilerContext context)
at IronPython.Runtime.PythonContext.CompilePythonCode(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink)
at IronPython.Runtime.PythonContext.GetScriptCode(SourceUnit sourceCode, String moduleName, ModuleOptions options, CompilationMode mode)
at IronPython.Runtime.PythonContext.GetScriptCode(SourceUnit sourceCode, String moduleName, ModuleOptions options)
at IronPython.Runtime.PythonContext.CompileModule(String fileName, String moduleName, SourceUnit sourceCode, ModuleOptions options, ScriptCode& scriptCode)
at IronPython.Runtime.PythonContext.CompileModule(String fileName, String moduleName, SourceUnit sourceCode, ModuleOptions options)
at IronPython.Runtime.Importer.LoadFromSourceUnit(CodeContext context, SourceUnit sourceCode, String name, String path)
at IronPython.Runtime.Importer.LoadModuleFromSource(CodeContext context, String name, String path)
at IronPython.Runtime.Importer.LoadFromDisk(CodeContext context, String name, String fullName, String str)
at IronPython.Runtime.Importer.ImportFromPathHook(CodeContext context, String name, String fullName, List path, Func`5 defaultLoader)
at IronPython.Runtime.Importer.ImportFromPath(CodeContext context, String name, String fullName, List path)
at IronPython.Runtime.Importer.ImportTopAbsolute(CodeContext context, String name)
at IronPython.Runtime.Importer.ImportModule(CodeContext context, Object globals, String modName, Boolean bottom, Int32 level)
at IronPython.Modules.Builtin.__import__(CodeContext context, String name, Object globals, Object locals, Object fromlist, Int32 level)
at Microsoft.Scripting.Interpreter.FuncCallInstruction`7.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run7[T0,T1,T2,T3,T4,T5,T6,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
at System.Dynamic.UpdateDelegates.UpdateAndExecute6[T0,T1,T2,T3,T4,T5,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
at IronPython.Runtime.Importer.ImportLightThrow(CodeContext context, String fullName, PythonTuple from, Int32 level)
at IronPython.Runtime.Operations.PythonOps.ImportTop(CodeContext context, String fullName, Int32 level)
at Microsoft.Scripting.Interpreter.FuncCallInstruction`4.Run(InterpretedFrame frame)
at Program.<Main>$(String[] args) in C:\Users\EvanN\Downloads\GoveeAPI-master\TestConsoleApp\Program.cs:line 15
我确定所有的路径都是正确的,我的C#脚本看起来像这样,我正在制作一个终端程序,以控制某些灯光,如果您想测试此类型 “ LC” “颜色代码” “ 255,0,0”
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Welcome User");
while(true) {
Console.ForegroundColor = ConsoleColor.White;
string UserMessage = Console.ReadLine();
if(UserMessage == "exit")
break;
Console.WriteLine("LP > " + Response(UserMessage));
}
string Response(string m) {
if(m == "help") {
Console.ForegroundColor = ConsoleColor.White;
return @"help - shows all commands
LC - Light Command enter a command to controll lights
LC COMMANDS
Color Code - enter color code to set all lights to
Color - Enter a color to set all leds to
HEX - Enter a hex to set all leds to";
} else if(m == "LC") {
Console.ForegroundColor = ConsoleColor.Yellow;
LightsAccess();
return "completed";
}
Console.ForegroundColor = ConsoleColor.Red;
return "PLEASE ENTER A VAILD COMMAND";
}
void LightsAccess() {
while (true) {
Console.ForegroundColor = ConsoleColor.Green;
string UserMessage = Console.ReadLine();
if(UserMessage != "exit") {
if(UserMessage == "Color Code") {
Console.WriteLine("LP-SL-A > Enter Color Code");
UserMessage = Console.ReadLine();
ScriptEngine engine = Python.CreateEngine();
ScriptScope scope = engine.CreateScope();
var searchPaths = engine.GetSearchPaths();
searchPaths.Add(@"C:\Python310\Lib");
engine.SetSearchPaths(searchPaths);
engine.ExecuteFile(@"C:\Users\EvanN\Downloads\GoveeAPI-master\TestConsoleApp\run.py", scope);
dynamic testFunction = scope.GetVariable("runscript");
var result = testFunction(UserMessage);
} else if(UserMessage == "Color") {
} else if(UserMessage == "HEX") {
} else
break;
Console.WriteLine("LP-SL-A > Color Applied");
}
}
}
这是给我错误的部分,
Console.WriteLine("LP-SL-A > Enter Color Code");
UserMessage = Console.ReadLine();
ScriptEngine engine = Python.CreateEngine();
ScriptScope scope = engine.CreateScope();
var searchPaths = engine.GetSearchPaths();
searchPaths.Add(@"C:\Python310\Lib");
engine.SetSearchPaths(searchPaths);
engine.ExecuteFile(@"C:\Users\EvanN\Downloads\GoveeAPI-master\TestConsoleApp\run.py", scope);
dynamic testFunction = scope.GetVariable("runscript");
var result = testFunction(UserMessage);
我的python脚本只有一行,
import os
谢谢您的时间,希望您能提供帮助
I am getting a error every time I run my iron python script. I am using windows 11 ironpython 2.7.12 and python 3.10. this is the error I get
Unhandled exception. Microsoft.Scripting.SyntaxErrorException: unexpected token 'from'
at IronPython.Runtime.ThrowingErrorSink.Add(SourceUnit sourceUnit, String message, SourceSpan span, Int32 errorCode, Severity severity)
at IronPython.Compiler.Parser.ReportSyntaxError(Int32 start, Int32 end, String message, Int32 errorCode)
at IronPython.Compiler.Parser.ReportSyntaxError(Token t, IndexSpan span, Int32 errorCode, Boolean allowIncomplete)
at IronPython.Compiler.Parser.ParsePrimary()
at IronPython.Compiler.Parser.ParsePower()
at IronPython.Compiler.Parser.ParseFactor()
at IronPython.Compiler.Parser.ParseExpr(Int32 precedence)
at IronPython.Compiler.Parser.ParseComparison()
at IronPython.Compiler.Parser.ParseNotTest()
at IronPython.Compiler.Parser.ParseAndTest()
at IronPython.Compiler.Parser.ParseOrTest()
at IronPython.Compiler.Parser.ParseExpression()
at IronPython.Compiler.Parser.ParseExpressionList(Boolean& trailingComma)
at IronPython.Compiler.Parser.ParseYieldExpression()
at IronPython.Compiler.Parser.ParseYieldStmt()
at IronPython.Compiler.Parser.ParseSmallStmt()
at IronPython.Compiler.Parser.ParseSimpleStmt()
at IronPython.Compiler.Parser.ParseStmt()
at IronPython.Compiler.Parser.ParseSuite()
at IronPython.Compiler.Parser.ParseIfStmtTest()
at IronPython.Compiler.Parser.ParseIfStmt()
at IronPython.Compiler.Parser.ParseStmt()
at IronPython.Compiler.Parser.ParseSuite()
at IronPython.Compiler.Parser.ParseLoopSuite()
at IronPython.Compiler.Parser.ParseForStmt()
at IronPython.Compiler.Parser.ParseStmt()
at IronPython.Compiler.Parser.ParseSuite()
at IronPython.Compiler.Parser.ParseIfStmtTest()
at IronPython.Compiler.Parser.ParseIfStmt()
at IronPython.Compiler.Parser.ParseStmt()
at IronPython.Compiler.Parser.ParseSuite()
at IronPython.Compiler.Parser.ParseClassOrFuncBody()
at IronPython.Compiler.Parser.ParseFuncDef()
at IronPython.Compiler.Parser.ParseStmt()
at IronPython.Compiler.Parser.ParseFileWorker(Boolean makeModule, Boolean returnValue)
at IronPython.Compiler.Parser.ParseFile(Boolean makeModule, Boolean returnValue)
at IronPython.Runtime.PythonContext.ParseAndBindAst(CompilerContext context)
at IronPython.Runtime.PythonContext.CompilePythonCode(SourceUnit sourceUnit, CompilerOptions options, ErrorSink errorSink)
at IronPython.Runtime.PythonContext.GetScriptCode(SourceUnit sourceCode, String moduleName, ModuleOptions options, CompilationMode mode)
at IronPython.Runtime.PythonContext.GetScriptCode(SourceUnit sourceCode, String moduleName, ModuleOptions options)
at IronPython.Runtime.PythonContext.CompileModule(String fileName, String moduleName, SourceUnit sourceCode, ModuleOptions options, ScriptCode& scriptCode)
at IronPython.Runtime.PythonContext.CompileModule(String fileName, String moduleName, SourceUnit sourceCode, ModuleOptions options)
at IronPython.Runtime.Importer.LoadFromSourceUnit(CodeContext context, SourceUnit sourceCode, String name, String path)
at IronPython.Runtime.Importer.LoadModuleFromSource(CodeContext context, String name, String path)
at IronPython.Runtime.Importer.LoadFromDisk(CodeContext context, String name, String fullName, String str)
at IronPython.Runtime.Importer.ImportFromPathHook(CodeContext context, String name, String fullName, List path, Func`5 defaultLoader)
at IronPython.Runtime.Importer.ImportFromPath(CodeContext context, String name, String fullName, List path)
at IronPython.Runtime.Importer.ImportTopAbsolute(CodeContext context, String name)
at IronPython.Runtime.Importer.ImportModule(CodeContext context, Object globals, String modName, Boolean bottom, Int32 level)
at IronPython.Modules.Builtin.__import__(CodeContext context, String name, Object globals, Object locals, Object fromlist, Int32 level)
at Microsoft.Scripting.Interpreter.FuncCallInstruction`7.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run7[T0,T1,T2,T3,T4,T5,T6,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
at System.Dynamic.UpdateDelegates.UpdateAndExecute6[T0,T1,T2,T3,T4,T5,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
at IronPython.Runtime.Importer.ImportLightThrow(CodeContext context, String fullName, PythonTuple from, Int32 level)
at IronPython.Runtime.Operations.PythonOps.ImportTop(CodeContext context, String fullName, Int32 level)
at Microsoft.Scripting.Interpreter.FuncCallInstruction`4.Run(InterpretedFrame frame)
at Program.<Main>$(String[] args) in C:\Users\EvanN\Downloads\GoveeAPI-master\TestConsoleApp\Program.cs:line 15
I am sure all the paths are correct for this my c# script looks like this I am making a terminal program to control some lights if you want to test this type
"LC"
"Color Code"
"255, 0, 0"
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Welcome User");
while(true) {
Console.ForegroundColor = ConsoleColor.White;
string UserMessage = Console.ReadLine();
if(UserMessage == "exit")
break;
Console.WriteLine("LP > " + Response(UserMessage));
}
string Response(string m) {
if(m == "help") {
Console.ForegroundColor = ConsoleColor.White;
return @"help - shows all commands
LC - Light Command enter a command to controll lights
LC COMMANDS
Color Code - enter color code to set all lights to
Color - Enter a color to set all leds to
HEX - Enter a hex to set all leds to";
} else if(m == "LC") {
Console.ForegroundColor = ConsoleColor.Yellow;
LightsAccess();
return "completed";
}
Console.ForegroundColor = ConsoleColor.Red;
return "PLEASE ENTER A VAILD COMMAND";
}
void LightsAccess() {
while (true) {
Console.ForegroundColor = ConsoleColor.Green;
string UserMessage = Console.ReadLine();
if(UserMessage != "exit") {
if(UserMessage == "Color Code") {
Console.WriteLine("LP-SL-A > Enter Color Code");
UserMessage = Console.ReadLine();
ScriptEngine engine = Python.CreateEngine();
ScriptScope scope = engine.CreateScope();
var searchPaths = engine.GetSearchPaths();
searchPaths.Add(@"C:\Python310\Lib");
engine.SetSearchPaths(searchPaths);
engine.ExecuteFile(@"C:\Users\EvanN\Downloads\GoveeAPI-master\TestConsoleApp\run.py", scope);
dynamic testFunction = scope.GetVariable("runscript");
var result = testFunction(UserMessage);
} else if(UserMessage == "Color") {
} else if(UserMessage == "HEX") {
} else
break;
Console.WriteLine("LP-SL-A > Color Applied");
}
}
}
this is the part that gives me the error
Console.WriteLine("LP-SL-A > Enter Color Code");
UserMessage = Console.ReadLine();
ScriptEngine engine = Python.CreateEngine();
ScriptScope scope = engine.CreateScope();
var searchPaths = engine.GetSearchPaths();
searchPaths.Add(@"C:\Python310\Lib");
engine.SetSearchPaths(searchPaths);
engine.ExecuteFile(@"C:\Users\EvanN\Downloads\GoveeAPI-master\TestConsoleApp\run.py", scope);
dynamic testFunction = scope.GetVariable("runscript");
var result = testFunction(UserMessage);
my python script only has one line
import os
thank you for your time I hope you can help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论