加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – IronPython:意外的令牌’来自’

发布时间:2020-12-15 22:43:34 所属栏目:百科 来源:网络整理
导读:我使用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 Mic
我使用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);
            }           
        }
    }
}

下面是我的输出

Unexpected token ‘from’

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

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

有没有其他方法可以在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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读