To install python-pptx, run python -m pip install python-pptx, then use it in code with from pptx import Presentation. The package is named python-pptx on PyPI, but you import it as pptx, and that mismatch causes most of the errors people hit.
The install command
python -m pip install python-pptx
The python-pptx documentation gives the shorter form pip install python-pptx. The python -m pip form does the same thing, but it guarantees pip belongs to the Python interpreter you named. The pip user guide says python -m pip "executes pip using the Python interpreter you specified as python", and on Windows it uses py -m pip instead:
py -m pip install python-pptx
pip also installs the dependencies. According to the documentation, python-pptx depends on lxml and Pillow, and on XlsxWriter only for the charting features. You do not install those yourself.
Check that it worked
This is the first example from the python-pptx Getting Started page. Save it as hello.py and run python hello.py:
from pptx import Presentation
prs = Presentation()
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "Hello, World!"
subtitle.text = "python-pptx was here!"
prs.save('test.pptx')
If it runs without an error, a one-slide test.pptx appears in the current folder. Open it in PowerPoint or another presentation program to confirm.
Which version you get
As of November 2026, PyPI lists python-pptx 1.0.2, released August 7, 2024, and says it requires Python 3.8 or later. To check what is installed in your environment:
python -m pip show python-pptx
To pin a specific version, use the == form from the pip user guide:
python -m pip install python-pptx==1.0.2
To move to the newest release, add --upgrade:
python -m pip install --upgrade python-pptx
A note on the documentation: the Installing page still says python-pptx "requires Python 2.7 or 3.3 or later". That text is out of date. Use the PyPI requirement (Python 3.8 or later) when deciding whether your interpreter is new enough.
Fix: ModuleNotFoundError: No module named 'pptx'
Example output:
Traceback (most recent call last):
File "hello.py", line 1, in <module>
from pptx import Presentation
ModuleNotFoundError: No module named 'pptx'
This means the Python that ran your script cannot see the package. There are three usual causes.
- pip and python point at different installations. A bare
pipcommand can belong to another Python than the one running your script. Install with the same interpreter, usingpython -m pip install python-pptx(orpy -m pipon Windows). Then run the script with that samepython. - A virtual environment is not active. If you installed inside a virtual environment, the script must run with that environment's Python. If you installed outside it, the environment will not see the package. Activate the environment, then install and run from there.
- You installed the wrong package.
pip install pptxis not the same name aspip install python-pptx. Installpython-pptx, and keep the import aspptx.
To see which interpreter and which packages you are working with, run python -c "import sys; print(sys.executable)" and python -m pip list, and compare the paths with where you installed.
Fix: naming your own file pptx.py
Python searches the script's own folder first. A file in your project called pptx.py, or a folder called pptx, can shadow the installed package. Rename it, and delete any __pycache__ folder next to it. The same applies to a script named python-pptx.py or anything else that matches the import name pptx.
Fix: pip cannot find or build the package
If pip reports that it cannot find a matching version, first check the Python version: python-pptx 1.0.2 requires Python 3.8 or later per PyPI, so an older interpreter cannot install it. Run python --version and switch to a newer interpreter if needed.
If you see error: externally-managed-environment on a Linux distribution or Homebrew Python, that is a separate protection against installing into the system Python. See Fix pip "error: externally-managed-environment". The short answer is to install inside a virtual environment.
Fix: errors from older python-pptx releases
Two problems in the release notes are worth knowing if your project pins an old version:
- Python 3.10 and newer on Windows. Release 0.6.22 (August 28, 2023) fixed an error reported as "module 'collections' has no attribute 'abc'". If you see that message with an older release, upgrade.
- Pillow version cap. Release 0.6.23 (November 2, 2023) removed a cap that limited Pillow to version 9.5 or lower, because that range carried a security vulnerability. Older releases can therefore pull in or conflict with an old Pillow.
Release 1.0.0 (August 3, 2024) added type annotations, and 1.0.1 added the py.typed marker so type checkers recognise them. Upgrading with python -m pip install --upgrade python-pptx is the first thing to try before debugging anything deeper.
Installing with a requirements file
To make the install repeatable, add a line to requirements.txt:
python-pptx==1.0.2
Then run python -m pip install -r requirements.txt. The details of that file format, and its own errors, are in pip install requirements.txt: How It Works and How to Fix Errors.
If it still fails
Copy the last line of the error message, which names the exception, and check it against the cases above. A ModuleNotFoundError is always about which Python is running. An error during pip install itself is about the Python version, the network, or a permissions block, and pip's own output says which. Run the install again with python -m pip install -v python-pptx for more detail.
Frequently asked questions
- Why do I install python-pptx but import pptx?
- The name on PyPI (python-pptx) and the name of the Python package inside it (pptx) are different. You install with pip install python-pptx and then write from pptx import Presentation. Running pip install pptx does not install this library.
- Which Python versions does python-pptx support?
- As of November 2026, PyPI lists version 1.0.2 (released August 7, 2024) as requiring Python 3.8 or later. The Installing page in the documentation still mentions Python 2.7, but it is out of date, so trust the PyPI metadata.
- Do I need to install lxml and Pillow myself?
- No. The documentation says pip installs the dependencies for you. python-pptx depends on lxml and Pillow, and on XlsxWriter if you use the charting features.
- Can python-pptx open .ppt files or convert slides to PDF?
- The documentation's Getting Started page covers creating and editing .pptx presentations. This article did not verify support for the older .ppt format or for PDF export, so check the python-pptx documentation before relying on either.