[Ironpython-users] Run a WPF application written in IronPython on the client computer without the install IronPython

sepatan at sibmail.com sepatan at sibmail.com
Mon Mar 19 09:17:43 CET 2012


I have a need to run a WPF application written in IronPython on the client
without installing IronPython.
 Technology to try to debug a standard example of WPF
.\IronPython-2.7.2.1\Tutorial.
 Baseline data:

1) The computer is not installed IronPython. From IronPython-2.7.2.1.zip
(download program) extracted in C:\IronPython

2) Create a C:\IronPython subdirectory pyc_d.

3) In the C:\IronPython\pyc_d created a file primer.py:

from avalon import *
import calculator
w = Window()
w.Title = "My Avalon Application"
w.Content = LoadXaml("calc.xaml")
calculator.enliven(w)
w.Show()

4)pyc_d contains:

IronPython.dll
IronPython.Modules.dll
IronPython.Wpf.dll
Microsoft.Scripting.dll

avalon.py
Calc.xaml
calculator.py
primer.py
pyc.py

5) Run ipy.exe, sequentially enter commands from the primer.py, it works :).

6) Next:
c:\IronPython\ipy.exe pyc.py /main:primer.py /target:exe /platform:x86
/standalone
I get primer.exe (4,09 МБ).

7) Run from the console, I get:
C:\IronPython\pyc_d>primer.exe

An unhandled exception: System.InvalidOperationException: The calling
thread must be STA, because many UI components require this.
   в Microsoft.Scripting.Interpreter.NewInstruction.Run(InterpretedFrame
frame)
   в Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   в Microsoft.Scripting.Interpreter.LightLambda.Run3[T0,T1,T2,TRet](T0
arg0, T1 arg1, T2 arg2)
  ...............................................................................
  All is not enumerate

It seems to do everything correctly. I take an example from the Tutorial,
the files from the Tutorial, to be going smoothly, but ... What is the
problem?

8)Try another option. Make a thin client in C #.
 Create a console C # project, and Program.cs:

using System;
using IronPython.Hosting;
using Microsoft.Scripting.Hosting;
using System.Reflection;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = Assembly.GetExecutingAssembly().Location;
            string dir = Directory.GetParent(path).FullName;

            ScriptEngine engine = Python.CreateEngine();
            ScriptSource source =
engine.CreateScriptSourceFromFile(Path.Combine(dir, args[0]));
            CompiledCode compiled = source.Compile();
            ScriptScope scope = engine.CreateScope();
            compiled.Execute(scope);
        }
    }
}

9) run:
C:\IronPython\pyc_d>ConsoleApplication1.exe primer.py

the same result: (Unhandled exception: System.InvalidOperationException:
The calling thread must be STA, because many UI components require this.)
 What is the problem?
 Are there any experts who can create learning (from Tutorial) WPF
application and run it on a machine without installing IronPython from
the console?
 Thank you.)



More information about the Ironpython-users mailing list