0

Recently, I tried using the python Excel functions on Windows with the win32com.client library. I installed it with :

pip install pywin32

I used it on my script, with simple commands like :

import os
import win32com.client as win32

ExcelApp = win32.gencache.EnsureDispatch("Excel.Application")
ExcelWrkBook = ExcelApp.ActiveWorkbook
ExcelWrkSht = ExcelWrkBook.ActiveSheet
ExcelWrkSht.Cells(5,3).Value = "something"

So it all worked just fine , till I got an Error like this out of nowhere :

Traceback (most recent call last): File "myscript.py", line 2, in import win32com.client as win32 File "C:\Users\Mycomputer\AppData\Local\Programs\Python\Python37-32\lib\site-packages\wi n32com\client__init__.py", line 11, in from . import gencache File "C:\Users\Mycomputer\AppData\Local\Programs\Python\Python37-32\lib\site-packages\wi n32com\client\gencache.py", line 660, in init() File "C:\Users\Mycomputer\AppData\Local\Programs\Python\Python37-32\lib\site-packages\wi n32com\client\gencache.py", line 60, in init _LoadDicts() File "C:\Users\Mycomputer\AppData\Local\Programs\Python\Python37-32\lib\site-packages\wi n32com\client\gencache.py", line 113, in _LoadDicts version = p.load() EOFError: Ran out of input

this pops up whenever I import win32com.client as win32, I tried reinstalling the library but it is still the same , Any idea ?

Aness
  • 610
  • 1
  • 7
  • 24

1 Answers1

4

It was a problem (client/ COM Server) communication, Solved by clearing the cache.

You can do it by deleting the gen_py folder "%userprofile%\AppData\Local\Temp\gen_py"

After debug the error was from GenCache. I am not that well informed with regards to these libraries but I found this interesting thread and replaced the gencache with Dispatch, so the Program changed to :

import os
import win32com.client as win32

ExcelApp = win32.Dispatch("Excel.Application")
ExcelWrkBook = ExcelApp.ActiveWorkbook
ExcelWrkSht = ExcelWrkBook.ActiveSheet
ExcelWrkSht.Cells(5,3).Value = "something"
testworks
  • 386
  • 1
  • 10
Aness
  • 610
  • 1
  • 7
  • 24