从 Iron Python 生成 .NET 程序集
我有一个 Iron Python 脚本,我想运行它,然后让 ipy 解释器输出一个可以在其他机器上运行的程序集。我该怎么做?是否有一个开关可以传递给 ipy.exe?
I have a Iron Python script that I want to run and then have the ipy interpreter output an assembly that I can run on other machines. How do I do that? Is there a switch I can pass to ipy.exe?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 SharpDevelop
一种方法是使用 SharpDevelop,它可以轻松构建程序集(可执行文件和类库) 。
该过程很简单:
.exe 和 .dll 文件将位于相关的构建输出目录中(调试或发布)。
使用 pyc.py
另一种方法是将 IronPython 命令行编译脚本称为 pyc.py。
编译脚本可以在以下目录中找到:
[IP_install_dir]\Tools\Scripts
用法:
ipy.exe pyc.py /main:Program.py Form.py /target:winexe
注意:要运行已编译的 exe,您将需要以下内容文件与可执行文件位于同一目录中:
Using SharpDevelop
One way to is to use SharpDevelop, it builds assemblies (executables and class libraries) easily.
The process is straightforward:
The .exe and .dll files will be in the relevant build output directory (Debug or Release).
Using pyc.py
Another way is to the IronPython command line compiler script called pyc.py.
The compiler script can be found in the directory:
[IP_install_dir]\Tools\Scripts
Usage:
ipy.exe pyc.py /main:Program.py Form.py /target:winexe
Note: To get the compiled exe to run you will need the following files in the same directory as your executable:
IronPython 附带了一个名为 Pyc 或 Python 命令行编译器的工具。如果您安装了 IronPython 的最新版本 2.6,则
pyc.py
将位于C:\Program Files (x86)\IronPython 2.6\Tools\Scripts
或您所在的任何位置在您的系统上安装了 IronPython。如果您有早期版本的 IronPython,则pyc.py
将在示例包中作为单独下载提供。使用 pyc.py,您可以从 Python 脚本创建控制台或 Windows 程序集。基本用法如下:
上面将生成一个名为
myprogram.exe
(/out) 的程序集,它是一个控制台应用程序 (/target),并将执行mainfile.py
中的代码code> 首先 (/main),并且还将在程序集中包含来自program.py
和support.py
的代码。There is a tool that ships with IronPython called Pyc or the Python Command-Line Compiler. If you installed the latest version 2.6 of IronPython, then
pyc.py
will be available atC:\Program Files (x86)\IronPython 2.6\Tools\Scripts
or wherever you installed IronPython on your system. If you have earlier versions of IronPython thenpyc.py
will be available as a separate download in the samples package.With
pyc.py
you can create console or Windows assemblies from your python scripts. Basic usage looks like this:The above will generate an assembly called
myprogram.exe
(/out) which is a console application (/target) and will execute the code inmainfile.py
first (/main) and will also include code fromprogram.py
andsupport.py
in the assembly.你也可以使用
asp.net来编译,如果你使用pyc.py来编译,你将无法导入模块。他们希望在2.6.2或更高版本中修复这个问题
you can also compile by using
for asp.net, if you use pyc.py to compile, you wont be able to import the modules.They expect to fix that in 2.6.2 or later