py2exe gtk 从目录执行脚本

发布于 2024-10-16 06:40:01 字数 381 浏览 2 评论 0原文

您好,我正在构建一个简单的应用程序,它将有一个组合框来选择位于脚本目录中的 python 脚本,以在数据库上创建报告。我打算使用 py2exe 来构建程序,这样用户就不必安装 python 和子模块。

那么我该如何让程序使用 py2exe dist 运行这些脚本呢?

我考虑过使用 system('command') 并从安装目录复制 python.exe 来运行 system(os.curdir+'python.exe ' + script_to_run) 然后 python.exe 将使用 python 的本地副本。 dll 和它需要运行的库(即 reportlab 和 pyobdc)可以

工作还是有更好的方法?

(如果更容易的话,我也不介意用ironpython构建它)

Hi I am building a simple application that will have a combo box to select python scripts that are in a directory called scripts to create reports on a database. I was going to use py2exe to build the program so that the users don't have to have python and submoduals installed.

so how would i go about having the program run these scripts using the py2exe dist?

i thought about using system('command') and copying the python.exe from my install directory to just run system(os.curdir+'python.exe ' + script_to_run) the python.exe would then use the local copy of the python.dll and the libs that it needs to run which would just be reportlab and pyobdc

would that work or is there a better way?

(i also wouldn't mind building it in ironpython if that would be easier)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

以为你会在 2024-10-23 06:40:01

Micheal Foord 有以下示例从 Ironpython 中嵌入 Ironpython

基本步骤是创建您的 shell 应用程序。对于真正的轻量级 GUI,有 EasyWPF。使用 pyc 将脚本编译为 exe,将标准库编译为 DLL。根据您是否需要从脚本中捕获标准输出或将信息中的变量传递给脚本,事情可能会变得更加复杂,如本文所述。下面列出了一个基本示例。

import clr
clr.AddReference('IronPython')
clr.AddReference('System')
clr.AddReference('mscorlib')
clr.AddReference('Microsoft.Scripting')
clr.AddReference('MyStandardLib')
#Now you can reference things like 'import lxml as L .....

from IronPython.Hosting import Python
from Microsoft.Scripting import SourceCodeKind

spath = "C:/fred.py"  # Path to script


engine = Python.CreateEngine()
#Now add your assemblies (like the standard library) to the engine
for assembly in clr.References:
    runtime.LoadAssembly(assembly)

source = engine.CreateScriptSourceFromFile(spath, SourceCodeKind.Statements)
mod = engine.CreateScope()
runtime = engine.Runtime

source.Execute(mod)

Micheal Foord has the following example for Embedding Ironpython from within Ironpython

The basic steps are to create your shell application. For a real lightweight GUI there is EasyWPF. Use pyc to compile your script to an exe and the standard library into a DLL. Depending on if you need to capture stdout from the scripts or pass variables in information into them, things can get more complicated as indicated in the article. A basic example is listed below.

import clr
clr.AddReference('IronPython')
clr.AddReference('System')
clr.AddReference('mscorlib')
clr.AddReference('Microsoft.Scripting')
clr.AddReference('MyStandardLib')
#Now you can reference things like 'import lxml as L .....

from IronPython.Hosting import Python
from Microsoft.Scripting import SourceCodeKind

spath = "C:/fred.py"  # Path to script


engine = Python.CreateEngine()
#Now add your assemblies (like the standard library) to the engine
for assembly in clr.References:
    runtime.LoadAssembly(assembly)

source = engine.CreateScriptSourceFromFile(spath, SourceCodeKind.Statements)
mod = engine.CreateScope()
runtime = engine.Runtime

source.Execute(mod)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文