Install & Compatibility
Where this runs
tested against v0.1.8 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.320s · 18.4MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.7s · import 0.270s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
convert
✓ from docx2pdf import convert
This quickstart demonstrates how to use the `convert` function for both single file and directory conversions. To run this code successfully, you must have Microsoft Word installed (on Windows or macOS) and provide actual .docx files/directories as input. The actual conversion calls are commented out to prevent errors in environments without Word or input files.
import os
from docx2pdf import convert
# This example demonstrates the API usage. For a full test,
# you need an actual 'example.docx' file in the current directory
# and Microsoft Word installed on your system (Windows/macOS).
# Example 1: Convert a single file
input_file = "example.docx" # Replace with your .docx file path
output_file = "example.pdf"
# Uncomment the following block to run if 'example.docx' exists
# if os.path.exists(input_file):
# print(f"Converting {input_file} to {output_file}...")
# try:
# convert(input_file, output_file)
# print("Conversion complete.")
# except Exception as e:
# print(f"Error during conversion: {e}")
# else:
# print(f"Skipping single file conversion: '{input_file}' not found.")
# Example 2: Convert all docx files in a directory
# For this, create a directory like './input_docs' with .docx files.
# input_dir = "./input_docs"
# output_dir = "./output_pdfs"
# if os.path.exists(input_dir):
# if not os.path.exists(output_dir):
# os.makedirs(output_dir)
# print(f"Converting all .docx files in '{input_dir}' to '{output_dir}'...")
# try:
# convert(input_dir, output_dir)
# print("Directory conversion complete.")
# except Exception as e:
# print(f"Error during directory conversion: {e}")
# else:
# print(f"Skipping directory conversion: '{input_dir}' not found.")
docx2pdf --version
Errors
Common errors & fixes
NotImplementedError: docx2pdf is not implemented for linux as it requires Microsoft Word to be installed
The `docx2pdf` library relies on a locally installed version of Microsoft Word to perform conversions and therefore does not support Linux or other non-Windows/macOS environments.
fixRun the conversion on a Windows or macOS machine with Microsoft Word installed, or use a different library/approach that supports Linux (e.g., LibreOffice, Pandoc).
'NoneType' object has no attribute 'SaveAs'
This error typically occurs on Windows when Microsoft Word cannot be launched by the script, often because no user is logged in, or the script is running as a service without desktop interaction.
fixEnsure a user is logged into the Windows machine, or consider running Word via scheduled tasks with appropriate user context. Alternatively, explore alternative conversion methods that don't require an active user session.
pywintypes.com_error
This is a general COM (Component Object Model) error on Windows, indicating a problem with Microsoft Word's automation interface. Common causes include Word not being installed, a corrupted or unopenable `.docx` file, Word being busy, or licensing issues.
fixEnsure Microsoft Word is installed and activated, try manually opening the `.docx` file to check for corruption, ensure Word isn't already open and busy, and verify file paths are not excessively long.
ImportError: DLL load failed while importing win32api: The specified module could not be found.
This error on Windows indicates that the `pywin32` library, a core dependency for `docx2pdf`'s Windows implementation, is not correctly installed or its DLLs cannot be found by Python.
fixReinstall `pywin32` (e.g., `pip install pywin32`) and run `python -m post_install` from an elevated command prompt to ensure COM components are correctly registered.
ModuleNotFoundError: No module named 'docx2pdf'
The 'docx2pdf' package has not been installed in your current Python environment.
fixInstall the library using pip: `pip install docx2pdf`
Upgrade
Version history
0.1.8latest on PyPI · released Dec 11, 2021
Audit
Dependencies
No dependency data recorded yet.