TypeError:此COM对象无法自动执行makepy流程-请为此对象手动运行makepy

时间:2019-07-14 18:57:08

标签: python pandas csv xlsm

什么样的错误?

跟踪错误

C:\Users\DELL\PycharmProjects\MyNew\venv\Scripts\python.exe 
C:/Users/DELL/PycharmProjects/MyNew/agaaaaain.py
Traceback (most recent call last):
  File "C:\Users\DELL\PycharmProjects\MyNew\venv\lib\site- 
packages\win32com\client\gencache.py", line 530, in EnsureDispatch
    ti = disp._oleobj_.GetTypeInfo()
pywintypes.com_error: (-2147418111, 'Call was rejected by callee.', None, 
None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/DELL/PycharmProjects/MyNew/agaaaaain.py", line 3, in 
<module>
excel = win32.gencache.EnsureDispatch('Excel.Application')
 File "C:\Users\DELL\PycharmProjects\MyNew\venv\lib\site- 
packages\win32com\client\gencache.py", line 541, in EnsureDispatch
raise TypeError("This COM object can not automate the makepy process - 
please run makepy manually for this object")
TypeError: This COM object can not automate the makepy process - please run 
makepy manually for this object

Process finished with exit code 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/DELL/PycharmProjects/MyNew/agaaaaain.py", line 3, in 
<module>
excel = win32.gencache.EnsureDispatch('Excel.Application')
  File "C:\Users\DELL\PycharmProjects\MyNew\venv\lib\site- 
packages\win32com\client\gencache.py", line 541, in EnsureDispatch
    raise TypeError("This COM object can not automate the makepy process - 
please run makepy manually for this object")
TypeError: This COM object can not automate the makepy process - please run 
makepy manually for this object

这是我的代码

import win32com.client as win32
excel = win32.gencache.EnsureDispatch('Excel.Application')

我正在使用PyCharm VirtualEnv

我没有找到任何解决方案,有人对此有想法吗?

注意:我如何尝试使用win32来访问excel工作簿,以便能够对其进行修改!..

2 个答案:

答案 0 :(得分:1)

遇到同样的问题并通过关闭所有正在运行的 Excel 应用程序来解决。

答案 1 :(得分:0)

您必须考虑从虚拟环境中运行代码。

并卸载环境之外的任何其他pywin32模块。

试一下!