question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Open existing pptx file

See original GitHub issue

python-pptx 0.5.7 Python 2.7.8

Currently using

f = open('C:\some_folder\my_file.pptx')
prs = Presentation(f)
f.close()

gives error: File is not a zip file

using

prs = Presentation('C:\\some_folder\\my_file.pptx')

gives error: Package not found at ‘C:\some_folder\my_file.pptx’

full stack traces below:

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\IPython\core\interactiveshell.py", line 3035, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-6-78857122896f>", line 2, in <module>
    prs = Presentation(f)
  File "C:\Python27\lib\site-packages\pptx\api.py", line 26, in __init__
    self._package = Package.open(pkg_file)
  File "C:\Python27\lib\site-packages\pptx\package.py", line 44, in open
    return super(Package, cls).open(pkg_file)
  File "C:\Python27\lib\site-packages\pptx\opc\package.py", line 122, in open
    pkg_reader = PackageReader.from_file(pkg_file)
  File "C:\Python27\lib\site-packages\pptx\opc\pkgreader.py", line 32, in from_file
    phys_reader = PhysPkgReader(pkg_file)
  File "C:\Python27\lib\site-packages\pptx\opc\phys_pkg.py", line 102, in __init__
    self._zipf = ZipFile(pkg_file, 'r')
  File "C:\Python27\lib\zipfile.py", line 770, in __init__
    self._RealGetContents()
  File "C:\Python27\lib\zipfile.py", line 811, in _RealGetContents
    raise BadZipfile, "File is not a zip file"
BadZipfile: File is not a zip file
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\IPython\core\interactiveshell.py", line 3035, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-7-4fbcdf1972de>", line 1, in <module>
    prs = Presentation('C:\\some_folder\\my_file.pptx')
  File "C:\Python27\lib\site-packages\pptx\api.py", line 26, in __init__
    self._package = Package.open(pkg_file)
  File "C:\Python27\lib\site-packages\pptx\package.py", line 44, in open
    return super(Package, cls).open(pkg_file)
  File "C:\Python27\lib\site-packages\pptx\opc\package.py", line 122, in open
    pkg_reader = PackageReader.from_file(pkg_file)
  File "C:\Python27\lib\site-packages\pptx\opc\pkgreader.py", line 32, in from_file
    phys_reader = PhysPkgReader(pkg_file)
  File "C:\Python27\lib\site-packages\pptx\opc\phys_pkg.py", line 32, in __new__
    "Package not found at '%s'" % pkg_file
PackageNotFoundError: Package not found at 'C:\some_folder\my_file.pptx'

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
sobolewskacommented, Aug 13, 2015
prs = Presentation('C:\\some_folder\\my_file.pptx')
f = open('C:\\some_folder\\my_file.pptx', 'rb')
Presentation(f)
f.close()

gives error when the presentation is EMPTY, there are 0 slides. adding at least 1 slide with empty content fixes the problem, and it is possible to open such presentation

1reaction
mfellowscommented, Aug 12, 2015

For the first method, using a file-like object, you need to open the file in binary mode:

f = open(r"C:\some_folder\my_file.pptx", "rb")
prs = Presentation(f)

Not sure why the second one (using the file path) failed though - double-check that the file exists?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with Presentations - python-pptx - Read the Docs
Actually, it only lets you make changes to existing presentations; it's just that ... python-pptx can open a presentation from a so-called file-like...
Read more >
PowerPoint can't open this file - Microsoft Support
In the Save as type box, choose Presentation (*.ppt). Then select Save. Now that the file is in .ppt format, you can open...
Read more >
How to Open a PowerPoint Presentation? [Complete Guide!]
To open or view an existing PowerPoint file, double-click on the file from the folder. Alternatively, open the PowerPoint application.
Read more >
PowerPoint 2016: Creating and Opening Presentations
To open an existing presentation: · Select the File tab to go to Backstage view, then click Open. Clicking Open · Click Browse....
Read more >
How to Open a PPT File Without Powerpoint
Click the “Open Existing Presentation” radio button and then click “Open.” Browse to where your PPT file is located and click “Open” to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found