2016-05-11 3 views
2

Ich versuche, mit docx-Datei in PDF zu konvertieren Code folgendeImport: kann nicht Namen COMError in Python importieren

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() 

Es ist ein Fehler zu werfen

ImportError: cannot import name COMError 

I comtypes Paket installiert haben.

Ich bin sehr neu zu Python, ich kann nicht herausfinden, wie dieses Problem gelöst wird.

[Bearbeiten]

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 
+0

anstelle von 'import comtypes.client' versuchen Sie' import comtypes'. comtypes.client importiert nur das Client-Paket. Der COMError könnte anderswo sein – Craicerjack

+0

@Craicerjack immer noch den gleichen Fehler –

+0

Wie haben Sie comtypes installiert? – Craicerjack

Antwort

1

Leider COMTypes für Windows konzipiert ist, nicht Linux.

comtypes allows to define, call, and implement custom and dispatch-based COM interfaces in pure Python. It works on Windows, 64-bit Windows, and Windows CE.

Source

Sie werden einen anderen Weg, um Ihre Umwandlung zu tun, wahrscheinlich durch eine andere Bibliothek finden müssen.