Microsoft.Scripting.SyntaxErrorException:使用IronPython导入PyPDF2时出现意外令牌'='

时间:2019-12-16 17:25:21

标签: c# ironpython

我在这里尝试导入PyPDF2库,但是下面的代码没有成功:

        var scriptEngine = Python.CreateEngine();
        var paths = scriptEngine.GetSearchPaths();

        paths.Add(@"C:\Python\Lib");
        paths.Add(@"C:\Python\Lib\site-packages");
        paths.Add(@"C:\Python\Lib\site-packages\PyPDF2");

        scriptEngine.SetSearchPaths(paths);

        var scriptScope = scriptEngine.CreateScope();
        scriptEngine.ExecuteFile(@"C:/scriptteste/convertpdf.py", scriptScope);
        var pdfToTxt = scriptScope.GetVariable("pdfTotxt");
        var streamOut = new MemoryStream();
        var streamErr = new MemoryStream();
        scriptEngine.Runtime.IO.SetOutput(streamOut, Encoding.Default);
        scriptEngine.Runtime.IO.SetErrorOutput(streamErr, Encoding.Default);
        scriptEngine.Operations.Invoke(pdfToTxt);

        Console.WriteLine("returned: {0}", scriptEngine.Operations.Invoke(pdfToTxt));
        Console.WriteLine("Press any key...");
        Console.ReadKey(true);

当我使用ExecuteFile方法运行该行时,发生错误。

Iron Python和PyPDF2之间不兼容吗?

我正在使用Python 3.7.5和IronPython 2.7.9

0 个答案:

没有答案