-
-
Save rdapaz/63590adb94a46039ca4a10994dff9dbe to your computer and use it in GitHub Desktop.
# If errors are found, do this | |
# clear contents of C:\Users\<username>\AppData\Local\Temp\gen_py | |
# that should fix it, to test it type | |
import win32com.client | |
app = win32com.client.gencache.EnsureDispatch('Word.Application') | |
app.Visible = True |
The following code will only delete the folder of the cache - it worked for me, but the better solution is "shutil" - earlier in this topic
try: xl = gencache.EnsureDispatch('Excel.Application') except AttributeError as ae: error_message = str(ae) if 'win32com.gen_py' in error_message: start = error_message.find('win32com.gen_py.')+len('win32com.gen_py.') tmp_em = error_message[start:] end = tmp_em.find("'") the_dir_to_remove = tmp_em[:end] if the_dir_to_remove in os.listdir(win32com.gen_path): win_gen_path_to_rm = win32com.gen_path+''+the_dir_to_remove print("Removing: ", win_gen_path_to_rm) recurcive_removal(win_gen_path_to_rm) else: print("unknown error of win32com") else: print("unknown error") print(ae)
@HeroOfStorm When putting code, it's better to put between triple backsticks with an optional language, like:
```python
... Your code
```
This will:
- Ensure correct indenting
- Avoid
__gen_path__
being replaced by gen_path (with bold and without underscores) - Provide syntax Highlighting
Hi, in my case, sudenly, it happens again, i tried all metods showed here and no luck, in the end, i realized that my microsoft 365 apps for enterprise had beed updated few days ago in windows control panel, just right click, change, quick repair, and thats it, it worked again!!
regards
@amarines2605 - I've deleted gen_py countless times as everyone seems to recommend... the quickfix for microsoft 365 was the piece I was missing. Thank you for the solution.
Remove-Item -path $env:LOCALAPPDATA\Temp\gen_py -recurse
work for me!!!!!!!!!!!! ty!
Note that the folder
gen_py
with the associated python version could be retrieved directly fromwin32com.__gen_path__
:Therefore, we could have the following code: