Last modified: Aug 23, 2026
Create PowerPoint with Python: Easy Guide
Creating presentations manually takes time. You repeat the same layout, format text, and insert images. Python can automate this entire process.
With the python-pptx library, you can build slides programmatically. This guide shows you how to create PowerPoint with Python from scratch. You will learn to add slides, text, and images quickly.
Why Use Python for PowerPoint?
Automation saves hours. If you need to generate weekly reports, you can run a script. It creates a consistent deck every time without errors.
Python also handles bulk operations. You can create 100 slides from a CSV file in seconds. This is impossible to do manually with accuracy.
The library is free and open-source. It works on Windows, macOS, and Linux. You only need basic Python knowledge to start.
Setting Up Your Environment
First, install the library. Open your terminal or command prompt. Run the following command:
pip install python-pptx
This installs the package and its dependencies. Verify the installation by checking the version.
python -c "import pptx; print(pptx.__version__)"
You should see a version number like 0.6.21 or higher. Now you are ready to create your first presentation.
Creating Your First Slide
Start with a simple blank presentation. The code below creates a slide with a title and subtitle.
from pptx import Presentation
# Create a presentation object
prs = Presentation()
# Use the first slide layout (Title Slide)
slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(slide_layout)
# Set the title text
title = slide.shapes.title
title.text = "Welcome to Python PPTX"
# Set the subtitle text
subtitle = slide.placeholders[1]
subtitle.text = "Automate your slide creation"
# Save the file
prs.save("first_slide.pptx")
print("Presentation created successfully!")
Run this script. You will see a file named first_slide.pptx in your directory. Open it with PowerPoint or Google Slides.
The Presentation() function creates a new empty deck. The slide_layouts property gives you access to predefined layouts. Index 0 is the title slide layout.
Adding Multiple Slides
Real presentations have many slides. You can loop through data to create slides dynamically. Here is an example with three content slides.
from pptx import Presentation
prs = Presentation()
# Use the Title and Content layout
slide_layout = prs.slide_layouts[1]
topics = ["Introduction", "Methods", "Results"]
for topic in topics:
slide = prs.slides.add_slide(slide_layout)
slide.shapes.title.text = topic
# Add bullet points to content placeholder
content = slide.placeholders[1]
tf = content.text_frame
tf.text = "First point about " + topic
tf.add_paragraph().text = "Second point about " + topic
prs.save("multi_slide.pptx")
print("Created " + str(len(prs.slides)) + " slides")
This script creates three slides. Each slide has a title and two bullet points. The add_paragraph() method adds new lines of text.
You can easily modify the list to include more topics. This is how you scale presentations for large datasets.
Adding Images to Slides
Visuals make presentations engaging. The python-pptx library supports image insertion. Use the add_picture() method on a slide.
from pptx import Presentation
from pptx.util import Inches
prs = Presentation()
slide_layout = prs.slide_layouts[6] # Blank layout
slide = prs.slides.add_slide(slide_layout)
# Add an image from a file
slide.shapes.add_picture("chart.png", Inches(1), Inches(1), width=Inches(5))
prs.save("with_image.pptx")
print("Image added successfully!")
You need an image file named chart.png in the same folder. The parameters are left position, top position, and width. Height adjusts automatically to maintain aspect ratio.
For a more detailed guide on positioning and resizing, check our Python PPTX Add Picture Guide. It covers advanced options like cropping and scaling.
Using Templates for Consistent Design
Starting from scratch is fine for simple decks. But for professional reports, you need a branded template. The library can open existing .pptx files and modify them.
from pptx import Presentation
# Open a template file
prs = Presentation("company_template.pptx")
# Add a slide using a layout from the template
slide_layout = prs.slide_layouts[1]
slide = prs.slides.add_slide(slide_layout)
slide.shapes.title.text = "Quarterly Report"
prs.save("report_from_template.pptx")
print("Template used successfully!")
This approach preserves the design, fonts, and logos. You only update the content. It ensures every slide matches your brand guidelines.
Learn more about this workflow in our Python PPTX: Use Template for Easy Slides article. It explains how to customize placeholders effectively.
Formatting Text and Paragraphs
Raw text is not enough. You often need bold, italics, or specific font sizes. The library allows full control over text formatting.
from pptx import Presentation
from pptx.util import Pt
prs = Presentation()
slide_layout = prs.slide_layouts[1]
slide = prs.slides.add_slide(slide_layout)
content = slide.placeholders[1]
tf = content.text_frame
tf.text = "Important notice"
# Access the paragraph and run for formatting
paragraph = tf.paragraphs[0]
run = paragraph.runs[0]
run.font.size = Pt(24)
run.font.bold = True
run.font.color.rgb = RGBColor(255, 0, 0)
prs.save("formatted.pptx")
print("Text formatted")
The run object represents a segment of text with uniform formatting. You can set size, bold, italic, and color. Use RGBColor to define custom colors.
Remember to import RGBColor from pptx.dml.color if you use colors.
Working with Tables and Charts
Data-heavy slides often require tables. The library supports creating tables directly on slides.
from pptx import Presentation
from pptx.util import Inches
prs = Presentation()
slide_layout = prs.slide_layouts[5] # Title Only
slide = prs.slides.add_slide(slide_layout)
slide.shapes.title.text = "Sales Data"
# Define table dimensions
rows, cols = 3, 3
left, top = Inches(2), Inches(2)
width, height = Inches(6), Inches(2)
table_shape = slide.shapes.add_table(rows, cols, left, top, width, height)
table = table_shape.table
# Fill table cells
data = [["Product", "Q1", "Q2"], ["A", "100", "150"], ["B", "200", "250"]]
for i in range(rows):
for j in range(cols):
table.cell(i, j).text = data[i][j]
prs.save("table_slide.pptx")
print("Table created")
Charts are more complex. The library does not natively support charts. You can use matplotlib to generate chart images, then insert them using the add_picture() method.
This combination gives you full flexibility. Generate a chart with matplotlib, save it as PNG, and add it to your slide.
Common Errors and Solutions
You might encounter a few issues. Here are the most common ones and how to fix them.
Error: File not found – Ensure the image or template path is correct. Use absolute paths if needed.
Error: Index out of range – This happens when you access a placeholder index that does not exist. Check the layout's placeholder count.
Error: Permission denied – Close the PowerPoint file if it is open. The script cannot overwrite a file that is in use.
Always test your script with a small sample before running it on a large dataset. This catches bugs early.
Conclusion
Creating PowerPoint with Python is straightforward. The python-pptx library gives you complete control over slides, text, and images.
You can automate repetitive tasks, generate reports, and maintain consistent branding. Start with simple scripts, then expand to complex layouts.
Remember to use templates for professional results. Explore the library's documentation for advanced features like animations and transitions.
Now you have the tools. Build your first automated presentation today and save hours of manual work.