'Microsoft.Scripting.SyntaxErrorException' 类型的未处理异常发生在 Microsoft.Dynamic.dll 意外标记 'part' 中

An unhandled exception of type 'Microsoft.Scripting.SyntaxErrorException' occurred in Microsoft.Dynamic.dll unexpected token 'part'

我正在尝试使用 Ironpython 从 c# 编写 运行 python 脚本,但出现标题中的错误。

这是代码部分。在 python

中导入时失败

c#

                var engine = Python.CreateEngine();
                var source = engine.CreateScriptSourceFromFile(templateLocation.Text + @"\test.py");
                var searchPaths = engine.GetSearchPaths();
                searchPaths.Add(templateLocation.Text+@"\Modules");
                engine.SetSearchPaths(searchPaths);
                List<String> argv = new List<String>();
                argv.Add(year.Text);
                argv.Add(filesLocation.Text);
                argv.Add(templateLocation.Text);
                argv.Add(reportLocation.Text);
                var scope = engine.CreateScope();
                engine.GetSysModule().SetVariable("argv", argv);
                source.Execute(scope);

Python

import sys
yearForm = sys.argv[0]
fileLocation = sys.argv[1].replace("\","/")
exeLocation = sys.argv[2].replace("\","/")
saveLocation = sys.argv[3].replace("\","/")
sys.path.insert(1,exeLocation+"/Modules/")
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import matplotlib.colors as cls
from matplotlib.colors import ListedColormap
from matplotlib.artist import setp
from pandas import ExcelWriter
import os

让我补充一下 exeLocation 是:C:\Users\Zlatko\name-annual-report

我能看到,你不能用 ironpython 执行这个 Python 脚本:一个原因是模块 Pandas 例如,Pandas 与 C[=12= 紧密相关].