clear_comtypes_cache.py breaks comtypes.client
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"
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.
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.
Running the script twice is another workaround. First run removes the directories, second run re-creates them.
@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.