comtypes icon indicating copy to clipboard operation
comtypes copied to clipboard

clear_comtypes_cache.py breaks comtypes.client

Open snoopyjc opened this issue 6 years ago • 3 comments

I was told to try running venv\scripts\clear_comtypes_cache.py with '-y' to fix the _Attribute not found exception. I tried it and it deleted the 'gen' directory, After that, 'import comtypes.client' gives 'ImportError: cannot import name 'gen''

I just tried it again without '-y' and it has the same issue:

(venv) H:\software\Powerpoint>python venv\scripts\clear_comtypes_cache.py
Remove comtypes cache directories? (y/n): y
Removed directory "H:\software\Powerpoint\venv\lib\site-packages\comtypes\gen"
Removed directory "C:\Users\JO2742\AppData\Roaming\Python\Python36\comtypes_cache"

snoopyjc avatar May 03 '19 14:05 snoopyjc

BTW, after this happens, even a 'pip uninstall comtypes', 'pip install comtypes' will not correct this. You have to DELETE your venv and reinstall everything from scratch. Use 'pip freeze' to see what you need to reinstall before deleting venv.

snoopyjc avatar May 03 '19 15:05 snoopyjc

Here is the workaround. After running the script, recreate the 'comtypes/gen' folder and create one file '__init__.py' with one comment in it: # comtypes.gen package, directory for generated files.

snoopyjc avatar May 03 '19 16:05 snoopyjc

Running the script twice is another workaround. First run removes the directories, second run re-creates them.

gwidion avatar Apr 28 '20 10:04 gwidion

@snoopyjc @gwidion

This should not happen now because _find_gen_dir is run when the client module is imported.

https://github.com/enthought/comtypes/blob/7e90e54d2131b35edef3e06f98f26a255f3dfa42/comtypes/client/init.py#L28-L29

https://github.com/enthought/comtypes/blob/7e90e54d2131b35edef3e06f98f26a255f3dfa42/comtypes/client/_code_cache.py#L23-L74

If the issue remains, please re-open.

junkmd avatar Dec 05 '22 12:12 junkmd