将IronPython WPF项目编译为exe [英] Compiling an IronPython WPF project to exe

查看:79
本文介绍了将IronPython WPF项目编译为exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

打包IronPython应用程序进行部署的最佳方法是什么?在网上搜索后,我想到的最好的事情(以及我目前正在做的事情)是使用clr.CompileModules()将整个项目的.py文件粘合到一个.dll中,然后只有一个run.py这将运行dll:

What is the best way to pack up an IronPython application for deployment? After scouring the web the best thing I've come up with (and what I'm currently doing) is using clr.CompileModules() to glue together my entire project's .py files into one .dll, and then having a single run.py do this to run the dll:

import clr
clr.AddReference('compiledapp.dll')

import app

这仍然不是最佳选择,因为这意味着我必须

This is still suboptimal, though, because it means I have to

  1. 分发3个文件(.dll.xamlrun.py启动器)
  2. 在主机上安装IronPython
  1. distribute 3 files (the .dll, the .xaml, and the run.py launcher)
  2. install IronPython on the host machine

此外,在IronPython已与Visual Studio 2010进行出色的集成之后,这感觉很...骇人听闻.对于为什么没有IPy应用程序的集成构建系统,我完全感到迷惑不解,因为这一切都归结为无论如何,IL.

Plus, this feels so... hacky, after the wonderful integration IronPython already has with Visual Studio 2010. I'm completely mystified as to why there is no integrated build system for IPy apps, seeing as it all boils down to IL anyway.

理想情况下,我希望能够将单个.exe.xaml合并到内部(我读到C#应用程序将XAML编译为BAML并将其合并到可执行文件中),而无需安装IronPython跑步.这至少有一半的可能吗? (我想如果该exe需要一些额外的.DLL或其他东西,就可以了.重要的部分是它采用.exe格式.)

Ideally, I want to be able to have a single .exe with the .xaml merged inside somehow (I read that C# apps compile XAML to BAML and merge them in the executable), and without requiring IronPython to be installed to run. Is this at least halfway possible? (I suppose it's ok if the exe needs some extra .DLLs with it or something. The important part is that it's in .exe form.)

一些澄清的内容:我尝试了 pyc.py ,但似乎并不承认我的项目不只是app.py的事实.它产生的exe的大小表明它只是编译" app.py,而没有在exe中包含任何其他文件.那么,如何告诉它编译项目中的每个文件?

Some edits to clarify: I have tried pyc.py, but it seems to not acknowledge the fact that my project is not just app.py. The size of the exe it produces suggests that it is just 'compiling' app.py without including any of the other files into the exe. So, how do I tell it to compile every file in my project?

为直观显示,这是我项目的解决方案资源管理器窗口的屏幕截图.

编辑II:不幸的是,似乎唯一的方法是使用pyc.py并将每个文件传递给它作为参数.对于这种方法,我有两个问题:

Edit II: It seems that unfortunately the only way is to use pyc.py and pass every single file to it as a parameter. There are two questions I have for this approach:

  1. 如何处理这么大的命令行?一个命令中最多可以包含256个字符.
  2. pyc.py如何知道保留包/文件夹结构?如上面的项目屏幕截图所示,编译后的程序如何知道如何访问子文件夹中的模块,例如访问DT \ Device?层次结构是否以某种方式保留"在dll中?


编辑III :由于通过命令行将70个文件名传递到pyc.py会很麻烦,并且为了更优雅地解决构建IPy项目的问题,我决定增加pyc.py.


Edit III: Since passing 70 filenames to pyc.py through the command line will be unwieldy, and in the interest of solving the problem of building IPy projects more elegantly, I've decided to augment pyc.py.

我添加了通过/pyproj:参数读取.pyproj文件,解析XML并从此处获取项目中使用的py文件列表的代码.这一直很好.但是,生成的可执行文件似乎无法访问属于我的项目的python子包(子文件夹).可以在以下位置找到具有.pyproj阅读支持补丁的pyc.py版本: http://pastebin.com/FgXbZY29

I've added code that reads in a .pyproj file through the /pyproj: parameter, parses the XML, and grabs the list of py files used in the project from there. This has been working pretty well; however, the executable produced seems to be unable to access the python subpackages (subfolders) that are part of my project. My version of pyc.py with my .pyproj reading support patch can be found here: http://pastebin.com/FgXbZY29

当这个新的pyc.py在我的项目上运行时,输出为:

When this new pyc.py is run on my project, this is the output:

c:\Projects\GenScheme\GenScheme>"c:\Program Files (x86)\IronPython 2.7\ipy.exe"
pyc.py /pyproj:GenScheme.pyproj /out:App /main:app.py /target:exe
Input Files:
        c:\Projects\GenScheme\GenScheme\__init__.py
        c:\Projects\GenScheme\GenScheme\Agent.py
        c:\Projects\GenScheme\GenScheme\AIDisplay.py
        c:\Projects\GenScheme\GenScheme\app.py
        c:\Projects\GenScheme\GenScheme\BaseDevice.py
        c:\Projects\GenScheme\GenScheme\BaseManager.py
        c:\Projects\GenScheme\GenScheme\BaseSubSystem.py
        c:\Projects\GenScheme\GenScheme\ControlSchemes.py
        c:\Projects\GenScheme\GenScheme\Cu64\__init__.py
        c:\Projects\GenScheme\GenScheme\Cu64\agent.py
        c:\Projects\GenScheme\GenScheme\Cu64\aidisplays.py
        c:\Projects\GenScheme\GenScheme\Cu64\devmapper.py
        c:\Projects\GenScheme\GenScheme\Cu64\timedprocess.py
        c:\Projects\GenScheme\GenScheme\Cu64\ui.py
        c:\Projects\GenScheme\GenScheme\decorators.py
        c:\Projects\GenScheme\GenScheme\DeviceMapper.py
        c:\Projects\GenScheme\GenScheme\DT\__init__.py
        c:\Projects\GenScheme\GenScheme\DT\Device.py
        c:\Projects\GenScheme\GenScheme\DT\Manager.py
        c:\Projects\GenScheme\GenScheme\DT\SubSystem.py
        c:\Projects\GenScheme\GenScheme\excepts.py
        c:\Projects\GenScheme\GenScheme\FindName.py
        c:\Projects\GenScheme\GenScheme\GenScheme.py
        c:\Projects\GenScheme\GenScheme\PMX\__init__.py
        c:\Projects\GenScheme\GenScheme\PMX\Device.py
        c:\Projects\GenScheme\GenScheme\PMX\Manager.py
        c:\Projects\GenScheme\GenScheme\PMX\SubSystem.py
        c:\Projects\GenScheme\GenScheme\pyevent.py
        c:\Projects\GenScheme\GenScheme\Scheme.py
        c:\Projects\GenScheme\GenScheme\Simulated\__init__.py
        c:\Projects\GenScheme\GenScheme\Simulated\Device.py
        c:\Projects\GenScheme\GenScheme\Simulated\SubSystem.py
        c:\Projects\GenScheme\GenScheme\speech.py
        c:\Projects\GenScheme\GenScheme\stdoutWriter.py
        c:\Projects\GenScheme\GenScheme\Step.py
        c:\Projects\GenScheme\GenScheme\TimedProcess.py
        c:\Projects\GenScheme\GenScheme\UI.py
        c:\Projects\GenScheme\GenScheme\VirtualSubSystem.py
        c:\Projects\GenScheme\GenScheme\Waddle.py
Output:
        App
Target:
        ConsoleApplication
Platform:
        ILOnly
Machine:
        I386
Compiling...
Saved to App

因此,它可以正确读取.pyproj中的文件列表...太好了!但是运行exe可以给我这个:

So it correctly read in the list of files in the .pyproj... Great! But running the exe gives me this:

Unhandled Exception: IronPython.Runtime.Exceptions.ImportException: 
No module named Cu64.ui

因此,即使Cu64\ui.py显然包含在编译中,该exe在运行时也找不到.这就是我在上一编辑中第二点所担心的.如何保存项目的包层次结构?也许可能需要分别编译每个软件包?

So even though Cu64\ui.py is obviously included in compilation, the exe, when run, can't find it. This is what I was afraid of in point #2 in the previous edit. How do I preserve the package hierarchy of my project? Perhaps compiling each package seperately may be needed?

我将扩大对这个问题的赏金.最终,我希望我们可以得到一个可以工作的pyc.py,它可以一步一步读取pyproj文件并生成可以运行的exe文件.然后,甚至可以将其提交到IronPython的代码库中,以包含在下一个发行版中……;]

推荐答案

我发布了一个Python脚本,该脚本可以获取IronPython文件,弄清其依赖性,然后将其编译成独立的二进制文件,位于Ironpython 2.6 .py-> .exe .希望你觉得它有用.它应该也支持WPF,因为它捆绑了WPF支持.

I posted a Python script which can take an IronPython file, figure out its dependencies and compile the lot into a standalone binary at Ironpython 2.6 .py -> .exe. Hope you find it useful. It ought to work for WPF too as it bundles WPF support.

这篇关于将IronPython WPF项目编译为exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆