C# 在Windows Phone 8中运行Python脚本/应用程序
我想在我的WindowsPhone8C#应用程序中运行用Python编写的SkeInformage切片器程序。我已经决定我可能应该使用IronPython来实现这一点,我已经决定我可以在安装IronPython时得到的ipy.exe终端中运行skeinforme。但我的问题是,我正在努力弄清楚如何在WindowsPhone8中使用IronPython托管和运行Python脚本。我还成功地在桌面Windows窗体应用程序中运行了一个简单的hello world脚本,该脚本使用以下代码将应用程序控制台输出传输到调试控制台:C# 在Windows Phone 8中运行Python脚本/应用程序,c#,windows-8,windows-phone-8,windows-phone,ironpython,C#,Windows 8,Windows Phone 8,Windows Phone,Ironpython,我想在我的WindowsPhone8C#应用程序中运行用Python编写的SkeInformage切片器程序。我已经决定我可能应该使用IronPython来实现这一点,我已经决定我可以在安装IronPython时得到的ipy.exe终端中运行skeinforme。但我的问题是,我正在努力弄清楚如何在WindowsPhone8中使用IronPython托管和运行Python脚本。我还成功地在桌面Windows窗体应用程序中运行了一个简单的hello world脚本,该脚本使用以下代码将应用程序控制
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DebugWriter debugW = new DebugWriter();
Console.SetOut(debugW);
}
private void button1_Click(object sender, EventArgs e)
{
TextWriter tw = new StreamWriter("Test.py");
tw.Write(scriptBox.Text);
tw.Close();
try
{
var ipy = Python.CreateRuntime();
dynamic test = ipy.UseFile("Test.py");
}
catch (Exception ex)
{
Debug.WriteLine("Error: " + ex.Message);
}
}
}
}
这是调试作者:
class DebugWriter : TextWriter
{
private StringBuilder content = new StringBuilder();
public DebugWriter()
{
Debug.WriteLine("Writing console to debug");
}
public override void Write(char value)
{
base.Write(value);
if (value == '\n')
{
Debug.WriteLine(content.ToString());
content = new StringBuilder();
}
else
{
content.Append(value);
}
}
public override Encoding Encoding
{
get { return System.Text.Encoding.UTF8; }
}
}
我甚至不知道如何将IronPython库添加到我的WindowsPhone8应用程序中,因为标准库不会导入。虽然我尝试过用主源代码编译显然已经失效的WindowsPhone7库,我可以导入这些库,但是当我尝试运行HelloWorld脚本时,调试终端上完全没有响应
你们中有谁知道如何在WindowsPhone8中实现这一点吗?如果你们知道如何在Windows8/Metro/RT中实现这一点,那么WP8可能也能实现这一点
更新:
我再次查看了调试输出,在尝试使用WP7库运行hello world脚本时,似乎出现了以下错误:
A first chance exception of type 'System.NotImplementedException' occurred in Microsoft.Scripting.DLL
Error: The method or operation is not implemented.
我设法让skeenforme在经过修改的IPY版本上运行。您可以在这里找到我的应用程序的源代码:Iron Python不支持Windows Phone 8—就这么简单。另外,如果库支持WP8,那并不意味着它自动支持Win8/RT。