2

ppt.py:

from pptx import Presentation

newPPT = Presentation()

newPPT.save("MyPPT.pptx")

converting to exe: cmd == pyinstaller --onefile ppt.py

once ready, the error is:

exception pptx.exc.PackageNotFoundError Raised when a package cannot be found at the specified path.

in the pptx package's doc.

is there a way to make it possible?

Thanks

Yevhen Kuzmovych
  • 10,940
  • 7
  • 28
  • 48
Med
  • 177
  • 1
  • 1
  • 8

1 Answers1

3

I had the same issue and finally figured how to fix it based on a similar issue: https://github.com/python-openxml/python-docx/issues/289

The solution is to edit the spec file. To generate the spec file (if you don't have one already) run:

pyi-makespec --onefile yourprogram.py

open and edit the sepc file:

# -*- mode: python ; coding: utf-8 -*-
import sys # added line
from os import path # added line
site_packages = next(p for p in sys.path if 'site-packages' in p) # added line

block_cipher = None

# add in template in datas
a = Analysis(['your_file.py'],
             pathex=['C:\\Users\\Desktop'],
             binaries=[],
             datas=[(path.join(site_packages,"pptx","templates"), "pptx/templates")],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
# rest of the file doesn't need any modification

Finally generate the exe with:

pyinstaller your_spec_file.spec

(Tested on windows 10 machine running python 3.6.4)

Ricardo
  • 350
  • 1
  • 10