Reputation: 510
I made some python scripts to control an external CATIA application. I now have to package those scripts into executable files but i can't manage to do it.
How to enforce win32com to use early binding for specific modules once scripts are built ?
My scripts controls a CATIA application using win32com.client module. I handle CATIA with late binding except the module CATIA V5 SpaceAnalysisInterfaces Object Library that contains functions with reference input/output arguments. For this one i use early binding, sadly the simple use of MakePy wasn't enought, i had to modify generated sources from the win32com.gen_py package to obtain a correct behavior from the input/output arguments. Now it works fine when i execute python scripts. But if i build them using either py2exe or cx_freeze the executable uses only late-binding so i get bad results.
Here's the way that i hook CATIA application and use its API :
import win32com.client
buff = [0, 0, 0]
catApp = win32com.client.GetActiveObject("CATIA.Application") # Late bind needed
doc = catApp .Documents.Open(path)
part = doc.Part # This property fails if using early binding
spa = doc.GetWorkbench(u"SPAWorkbench")
I = spa.Inertias.Add(part) # Early bind needed
cogCoords = I.GetCOGPosition(buff) # The damn input/ouput argument function
And here's my build script using cx_freeze :
from cx_Freeze import setup, Executable
options = {
"includes": [],
"excludes": [],
"packages": ["win32com.gen_py"]
}
target = Executable(
script = "test.py",
base = "Console",
compress = True,
icon = None,
)
setup(
name = "Test",
version = "1.0",
description = "Early Binding Test Built",
author = "C.LECLERC",
options = {"build_exe": options},
executables = [target]
)
This build script generate a bunch of files including the content of my actual win32com.gen_py module so it should works. But when i execute the file it uses only late binding. I couldn't check if the files are correctly added when i use py2exe but the behavior is exactly the same : late bind !
I took a look at this post but my problem is different. Modules are correctly copied and scripts doesn't raise exceptions. The input/output functions just doesn't works correctly.
Any help would be appreciated.
Upvotes: 2
Views: 751
Reputation: 510
I answer my own question to share the solution i found and flag the problem as resolved.
Just copy the 'dicts.dat' file from the win32com.gen_py package to the equivalent folder of the 'library.zip' archive generated by cx_freeze.
Upvotes: 1