Skip to content

Error CoInitialize has not been called (Threading?) #759

@EnomisRekschil

Description

@EnomisRekschil

calling

import xlwing as xw
xw.Book()

I get the following error:
Traceback (most recent call last):
File "", line 1, in
File "C:\Anaconda2\lib\site-packages\xlwings\main.py", line 479, in init
app = App(add_book=False)
File "C:\Anaconda2\lib\site-packages\xlwings\main.py", line 204, in init
self.impl = xlplatform.App(spec=spec, add_book=add_book)
File "C:\Anaconda2\lib\site-packages\xlwings_xlwindows.py", line 288, in init
self.xl = COMRetryObjectWrapper(DispatchEx('Excel.Application'))
File "C:\Anaconda2\lib\site-packages\win32com\client_init
.py", line 114, in DispatchEx
dispatch = pythoncom.CoCreateInstanceEx(clsid, None, clsctx, serverInfo, (pythoncom.IID_IDispatch,))[0]
com_error: (-2147221008, 'CoInitialize has not been called.', None, None)

Which I "solved" by adding pythoncom.CoInitialize() to the method DispatchEx in "C:\Anaconda2\lib\site-packages\win32com\client_init_.py" before calling pythoncom.CoCreateInstanceEx(...) (source)
Probably this is not the most elegant solution... Do you know anything better?

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions