I need to convert .doc files to .docx within my code itself . I have done it using comtypes.client but this library basically requires Windows and Microsoft Word to be installed . What would be the best package in python that could do the conversion without the need of windows and office word. Pandoc looks good but it doesn't support .doc files.

2 Answers 2


If you have LibreOffice installed, you can call it directly with subprocess:

import subprocess
import os

for filename in os.listdir(os.getcwd()):
    if filename.endswith('.doc'):
        subprocess.call(['soffice', '--headless', '--convert-to', 'docx', filename])

This will convert all the files in the current directory with names ending in .doc to .docx format.

Beware, you must close open instances of LibreOffice before running this, or it will exit silently without doing anything. This is a known bug.



You could use unoconv and convert the files through LibreOffice. It is imperfect, and some formatting is lost, but it will convert all doc files to docx with

unoconv -d document --format=docx *.doc

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.