I am migrating scripts from Python 2.7 to 3.9.
This line causes problems:
EA = gencache.EnsureModule('{64FB2BF4-9EFA-11D2-8307-C45586000000}', 0, 2, 10)
The above code is creating and loading the COM module in python 2.7. When I am run the same script on 3.9, it throws the below error.
Traceback (most recent call last):
File "C:\Users\<user name>\Projects\EAtool\EAGeneratorUpgraded\EAgenerator_27.py", line 60, in <module>
EA = gencache.EnsureModule('{64FB2BF4-9EFA-11D2-8307-C45586000000}', 0, 2, 10)
File "C:\Users<user name>\AppData\Local\miniconda3\envs\EAGeneratorUpgraded\lib\site-packages\win32com\client\gencache.py", line 601, in EnsureModule
module = MakeModuleForTypelib(
File "C:\Users<user name>\AppData\Local\miniconda3\envs\EAGeneratorUpgraded\lib\site-packages\win32com\client\gencache.py", line 318, in MakeModuleForTypelib
makepy.GenerateFromTypeLibSpec(
File "C:\Users<user name>\AppData\Local\miniconda3\envs\EAGeneratorUpgraded\lib\site-packages\win32com\client\makepy.py", line 330, in GenerateFromTypeLibSpec
gen.generate(fileUse, bForDemand)
File "C:\Users<user name>\AppData\Local\miniconda3\envs\EAGeneratorUpgraded\lib\site-packages\win32com\client\genpy.py", line 1092, in generate
self.do_generate()
File "C:\Users<user name>\AppData\Local\miniconda3\envs\EAGeneratorUpgraded\lib\site-packages\win32com\client\genpy.py", line 1191, in do_generate
oleitem.WriteClass(self)
File "C:\Users<user name>\AppData\Local\miniconda3\envs\EAGeneratorUpgraded\lib\site-packages\win32com\client\genpy.py", line 339, in WriteClass
self.WriteClassBody(generator)
File "C:\Users<user name>\AppData\Local\miniconda3\envs\EAGeneratorUpgraded\lib\site-packages\win32com\client\genpy.py", line 682, in WriteClassBody
assert enumEntry.desc.desckind == pythoncom.DESCKIND_FUNCDESC
AssertionError
I have deleted the gen_py folder and rerun the code as suggested in python-win32com excel com model started generating errors.
Later, I tried to use the below piece of code, to delete the gen_py via script, but still end up with the same Assertion error from gen.py:
for attempt in range(2):
try:
# Attempt to load the COM library for Enterprise Architect
print("Attempting to load COM library...")
EA = gencache.EnsureModule('{64FB2BF4-9EFA-11D2-8307-C45586000000}', 0, 2, 10)
except Exception as e:
temp_data_dir = os.environ.get('LOCALAPPDATA')
gen_py_dir = ''
for curr_path, dirs, files, in os.walk(temp_data_dir):
if 'gen_py' in dirs:
gen_py_dir = Path(curr_path).joinpath('gen_py')
print(gen_py_dir)
break
if gen_py_dir and gen_py_dir.exists():
shutil.rmtree(gen_py_dir)
print(f"Deleted directory: {gen_py_dir}")
I have also verified the type library for EA tool.The below image contains the CLSID info and version details.
How should I migrate my code with the the win32com module from Python 2.7 to Python 3.9?