c# – IronPython:意外的令牌’来自’
我使用Iron
Python从.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<string> searchPaths = new List<string>(); searchPaths.Add(@"C:UsersAdminAppDataLocalProgramsPythonPython35Lib)"); searchPaths.Add(@"C:UsersAdminAppDataLocalProgramsPythonPython35Libsite-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 有没有其他方法可以在IronPython 2.7中导入tensorflow或在.net中运行Python? 解决方法
Prakash – 正如您在文档中发现的那样,TensorFlow在Windows上运行时需要Python 3.5或3.6.它不会在IronPython 2.7中运行.
GitHub上的一个用户成功(有大量的工作和不容易做的)方式got TF running on Windows under Python2.7,你可能能够建立他们的工作,但这并不是你想要的IronPython解决方案.我最好的建议是使用3.5或3.6. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |