How to Install python-docx in Python
Create, read, and update Microsoft Word .docx files.
pip install python-docx
What is python-docx?
Create, read, and update Microsoft Word .docx files.
python-docx is a Python library for reading, creating, and updating Microsoft Word 2007+ (.docx) files.
More information is available in the python-docx documentation
Quick Start
Minimal example to get started with python-docx:
import docx
print(docx.__version__)
Installation
pip (standard)
pip install python-docx
Virtual environment (recommended)
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install python-docx
pip3
pip3 install python-docx
conda
conda install -c conda-forge python-docx
Poetry
poetry add python-docx
Dependencies
Installing python-docx will also install these packages:
Verify the Installation
After installing, confirm the package is available:
python -c "import docx; print(docx.__version__)"
If this prints a version number, installation succeeded. If you see a ModuleNotFoundError, see the errors section below.
Installation Errors
Common errors when installing python-docx with pip.
ModuleNotFoundError: No module named 'docx'
Cause: The package is not installed in the current Python environment.
Fix: Run pip install python-docx. If using a virtual environment, ensure it is activated first.
ModuleNotFoundError: No module named 'docx' (installed but still failing)
Cause: pip installed the package into a different Python than the one running your script.
Fix: Use python -m pip install python-docx to install into the interpreter you are running.
ImportError: cannot import name 'X' from 'docx'
Cause: The function or class does not exist in the installed version.
Fix: Check the version with pip show python-docx and upgrade with pip install --upgrade python-docx.
pip: command not found
Cause: pip is not in PATH or Python was not added to PATH during installation.
Fix: Try python -m pip install python-docx. On macOS/Linux try pip3.
PermissionError: [Errno 13] Permission denied
Cause: No write access to the system Python package directory.
Fix: Use a virtual environment, or add --user: pip install --user python-docx
SSL: CERTIFICATE_VERIFY_FAILED
Cause: pip cannot verify PyPI's SSL certificate — common behind corporate proxies.
Fix: Try: pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org python-docx
Recent Releases
| Version | Released |
|---|---|
1.2.0 latest |
2025-06-16 |
1.1.2 |
2024-05-01 |
1.1.1 |
2024-04-30 |
1.1.0 |
2023-11-04 |
1.0.1 |
2023-10-12 |
Manage python-docx
Upgrade to latest version
pip install --upgrade python-docx
Install a specific version
pip install python-docx==1.2.0
Uninstall
pip uninstall python-docx
Check what is installed
pip show python-docx