ImportError: cannot import COMError name in python

I am trying to convert a docx file to pdf with the following code

import sys import os import comtypes.client wdFormatPDF = 17 in_file = os.path.abspath(sys.argv[1]) out_file = os.path.abspath(sys.argv[2]) word = comtypes.client.CreateObject('Word.Application') doc = word.Documents.Open(in_file) doc.SaveAs(out_file, FileFormat=wdFormatPDF) doc.Close() word.Quit() 

Throws an error

 ImportError: cannot import name COMError 

I installed the comtypes package.

I am very new to python, I cannot figure out how to solve this problem.

[change]

Stacktrace

 Traceback (most recent call last): File "converttopdf.py", line 3, in <module> import comtypes.client File "/usr/local/lib/python2.7/dist-packages/comtypes-1.1.2-py2.7.egg/comtypes/__init__.py", line 23, in <module> from _ctypes import COMError ImportError: cannot import name COMError 
+2
source share
1 answer

Unfortunately, COMTypes is for Windows, not Linux.

comtypes allows you to define, invoke, and implement user and dispatch COM interfaces in pure Python. It runs on Windows, 64-bit Windows, and Windows CE.

A source

You will need to find another way to do your conversion, probably through another library.

+1
source

Source: https://habr.com/ru/post/1272778/


All Articles