Last modified: Aug 23, 2026
Convert PPT to PPTX with Python
Old PowerPoint files end with the .ppt extension. Newer versions use .pptx. Many modern tools only work with .pptx. So you often need to convert your files.
Doing this manually is slow. If you have hundreds of files, it takes forever. Python can automate this task. You can convert many files in seconds. This guide shows you how.
Why Convert PPT to PPTX?
The .ppt format is from PowerPoint 97-2003. It is outdated. The .pptx format is the modern standard. It is based on XML. This makes it more stable and secure.
Many Python libraries, like python-pptx, only read .pptx files. If you want to edit slides with code, you must convert first. Also, some cloud services reject .ppt files. Converting ensures compatibility everywhere.
Method 1: Using LibreOffice
LibreOffice is a free office suite. It can run in headless mode. This means it works without a visible window. You can call it from Python. This is the most reliable method.
First, install LibreOffice on your system. Then, you can use the subprocess module in Python. This module lets you run external commands.
Here is a simple script to convert one file. We use the soffice command. This is the LibreOffice executable.
import subprocess
import os
def convert_ppt_to_pptx(input_path, output_dir):
# Ensure the output directory exists
os.makedirs(output_dir, exist_ok=True)
# Build the LibreOffice command
command = [
'soffice',
'--headless',
'--convert-to', 'pptx',
'--outdir', output_dir,
input_path
]
# Run the command
result = subprocess.run(command, capture_output=True, text=True)
# Check if it worked
if result.returncode == 0:
print(f"Success: {input_path}")
else:
print(f"Error: {result.stderr}")
# Example usage
convert_ppt_to_pptx('old_presentation.ppt', 'converted_files/')
This script is straightforward. It takes the input file path and output folder. It creates the folder if needed. Then it runs the conversion. The --headless flag prevents any GUI from opening.
Method 2: Batch Conversion
You rarely have just one file. You usually have a folder full of them. We can modify the script to handle multiple files. This saves a lot of time.
We use the glob module to find all .ppt files. Then we loop through each one. Here is the improved code.
import subprocess
import glob
import os
def convert_all_ppt_files(input_dir, output_dir):
# Find all .ppt files (not .pptx)
ppt_files = glob.glob(os.path.join(input_dir, '*.ppt'))
# Ensure output directory exists
os.makedirs(output_dir, exist_ok=True)
# Convert each file
for file_path in ppt_files:
command = [
'soffice',
'--headless',
'--convert-to', 'pptx',
'--outdir', output_dir,
file_path
]
result = subprocess.run(command, capture_output=True, text=True)
if result.returncode == 0:
print(f"Converted: {os.path.basename(file_path)}")
else:
print(f"Failed: {os.path.basename(file_path)}")
# Example: convert all files in 'slides/' folder
convert_all_ppt_files('slides/', 'converted/')
This script is efficient. It finds all files ending with .ppt. It ignores .pptx files. This prevents errors. You can run this on a whole directory in one go.
Method 3: Using COM Automation (Windows Only)
If you are on Windows, you have another option. You can use COM automation. This directly controls Microsoft PowerPoint. It requires PowerPoint to be installed.
This method is very accurate. It uses the official PowerPoint engine. The output is identical to opening and saving in PowerPoint. Here is how it works.
import win32com.client
import os
def convert_with_powerpoint(input_path, output_dir):
# Start PowerPoint application
powerpoint = win32com.client.Dispatch("PowerPoint.Application")
# Open the presentation
presentation = powerpoint.Presentations.Open(input_path)
# Build the output file path
base_name = os.path.splitext(os.path.basename(input_path))[0]
output_path = os.path.join(output_dir, base_name + '.pptx')
# Save as pptx (format 24 is for pptx)
presentation.SaveAs(output_path, 24)
# Close and quit
presentation.Close()
powerpoint.Quit()
print(f"Converted: {output_path}")
# Example usage
convert_with_powerpoint('old_file.ppt', 'output_folder/')
This code requires the pywin32 library. Install it with pip install pywin32. The number 24 in SaveAs is the format code for .pptx. This is a very reliable method.
Handling Errors and Edge Cases
Conversion is not always perfect. Sometimes files are corrupted. Sometimes they have password protection. You should handle these cases.
For LibreOffice, you can check the return code. A non-zero code means an error. For COM automation, wrap your code in a try block. This catches any exceptions.
import subprocess
def safe_convert(input_path, output_dir):
try:
command = [
'soffice',
'--headless',
'--convert-to', 'pptx',
'--outdir', output_dir,
input_path
]
result = subprocess.run(command, capture_output=True, timeout=30)
if result.returncode == 0:
return True
else:
# Log the error
print(f"Error for {input_path}: {result.stderr}")
return False
except subprocess.TimeoutExpired:
print(f"Timeout for {input_path}")
return False
# Use the safe function
success = safe_convert('problem_file.ppt', 'output/')
print(f"Conversion success: {success}")
Always add error handling. It makes your script robust. You can also log errors to a file. This helps you find problem files later.
Performance Tips
Converting many files can be slow. LibreOffice starts slowly. Each conversion takes a few seconds. Here are some tips to speed things up.
Keep the soffice process running. You can use the --invisible flag with a listening port. This is advanced, but it saves startup time. For most users, the simple loop is fine.
You can also use parallel processing. The concurrent.futures module helps. But be careful. LibreOffice may not handle multiple instances well. Start with sequential processing.
After conversion, you can use the python-pptx library to edit your slides. This is a great next step. You can add images or use templates for better design. Check out our guide on Python PPTX Add Picture Guide to enhance your slides.
Testing Your Conversion
Always test your converted files. Open them in PowerPoint or LibreOffice. Check the formatting. Sometimes complex animations break. Images might shift slightly.
The best way to test is programmatically. Use python-pptx to open the new file. Count the slides. Check the text. This ensures the conversion worked correctly.
from pptx import Presentation
# Open the converted file
prs = Presentation('converted/presentation.pptx')
# Check how many slides it has
print(f"Number of slides: {len(prs.slides)}")
# Verify first slide
first_slide = prs.slides[0]
for shape in first_slide.shapes:
if shape.has_text_frame:
print(f"Text: {shape.text_frame.text[:50]}")
This validation script gives you confidence. It confirms the file is a valid .pptx. If you plan to use templates, read our Python PPTX: Use Template for Easy Slides guide. It will save you time.
Conclusion
Converting .ppt to .pptx with Python is simple. You have three main options. LibreOffice works everywhere. COM automation is great for Windows. Both are reliable.
Start with the LibreOffice method. It is free and cross-platform. The code is short and easy to understand. You can adapt it for your needs.
Remember to handle errors. Test your output files. This ensures quality. With these scripts, you can automate the entire process. You will save hours of manual work.
Now you can convert files, then use python-pptx to edit them. This opens up many possibilities for automation. Your workflow will be much smoother.