IronPython:意外的令牌’来自’

我使用IronPython从.net运行python脚本,下面是我的python脚本

import tensorflow as tf print('Tensorflow Imported') 

下面是C#代码

 using System; using System.Text; using System.IO; using IronPython.Hosting; using System.Collections.Generic; using Microsoft.Scripting.Hosting; namespace ConsoleApplication1 { class Program { private static void Main() { var py = Python.CreateEngine(); List searchPaths = new List(); searchPaths.Add(@"C:\Users\Admin\AppData\Local\Programs\Python\Python35\Lib)"); searchPaths.Add(@"C:\Users\Admin\AppData\Local\Programs\Python\Python35\Lib\site-packages)"); py.SetSearchPaths(searchPaths); try { py.ExecuteFile("script.py"); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } } 

下面是我的输出

意外的令牌’来自’

如果我删除import语句然后python脚本执行正常。 我试过包括os,sys所有那些导入没有任何问题。 我通过pip安装了TensorFlow,当我通过python控制台(v3.5)运行上面的脚本时,它工作正常。

更新 :在TF doc中,其写的“ TensorFlow仅支持Windows上的3.5.x版本的Python ”。 但正式发布的IronPython是版本2.7我很高兴在GitHub上找到IronPython,尝试构建它(我只是在控制台中键入内置并且被它显示的长错误消息列表吓坏了!:D找不到预编译二进制

有什么替代方法可以在IronPython 2.7中导入tensorflow或在.net中运行Python吗?

Prakash – 正如您在文档中发现的那样,TensorFlow在Windows上运行时需要Python 3.5或3.6。 它不会在IronPython 2.7中运行。

GitHub上的一个用户成功(有大量的工作和不容易做的)方式在TF2上运行TF在Python2.7下运行 ,你可能能够在他们的工作基础上进行构建,但这并不是解决方案你在寻找IronPython。 我最好的建议是使用3.5或3.6。