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)
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)