有没有一种方法可以将pptxpython与PythonVerion3.7结合使用,并使用pyinstaller生成exe?

2024-09-30 12:20:25 发布

您现在位置:Python中文网/ 问答频道 /正文

ppt.py:

from pptx import Presentation

newPPT = Presentation()

newPPT.save("MyPPT.pptx")

转换为exe:cmd == pyinstaller --onefile ppt.py

准备就绪后,错误为:

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

在pptx包的doc

有没有办法让它成为可能

谢谢


Tags: frompyimportcmdsave错误presentationexe
1条回答
网友
1楼 · 发布于 2024-09-30 12:20:25

我遇到了同样的问题,并最终根据一个类似的问题找到了解决方法:https://github.com/python-openxml/python-docx/issues/289

解决方案是编辑等级库文件。 要生成等级库文件(如果尚未生成等级库文件),请运行:

pyi-makespec  onefile yourprogram.py

打开并编辑sepc文件:

# -*- 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

最后使用以下命令生成exe:

pyinstaller your_spec_file.spec

(在运行python 3.6.4的windows 10计算机上测试)

相关问题 更多 >

    热门问题