【发布时间】:2014-08-02 22:09:18
【问题描述】:
我在 EMF 图像格式、python PIL(以及 Pillow)图像库和用于将 Python 打包成 Windows 可执行文件的 Pyinstaller 程序的交集处遇到了一个特殊问题。
我有一个使用 PIL/Pillow 将 EMF 文件转换为 JPEG 的脚本。当我在 python 中运行 python 脚本时,这可以正常工作。但是,当我使用 Pyinstaller.exe -F 将其打包成 EXE 时,它不起作用。
使用 Pillow 版本时,我收到一个简单的错误提示
“无法转换 image1.emf”。
使用 PIL 版本,我收到一条更长的消息:
Traceback(最近一次调用最后一次): 文件“”,第 38 行,在 文件“”,第 27 行,在 convertImageFile 文件“C:\Embibe\Git\content-ingestion\src\build\convertImage\out00-PYZ.pyz\PIL .Image”,第 2126 行,打开 IOError:无法识别图像文件'image1.emf'
有没有其他人遇到过这个问题并找到了可行的解决方案?
下面是血淋淋的细节,如果你需要的话……:-)
操作系统:Windows 7 64 位(但所有软件都是 32 位)
软件:: Python:2.7.5, Pyinstaller:2.1, PIL: 内置 Python, Pillow: 2.4.0
Python 脚本convImg.py:
from __future__ import print_function
import os, sys
from PIL import Image
for infile in sys.argv[1:]:
f, e = os.path.splitext(infile)
outfile = f + ".jpg"
if infile != outfile:
try:
Image.open(infile).convert('RGB').save(outfile)
except IOError:
print("cannot convert", infile)
运行为:convImg.py image1.emf 正常工作并生成 image1.jpg。
当使用 \python27\scripts\pyinstaller.exe -F convImg.py 打包到 exe 并以 convImg.exe image1 运行时,会出现上面列出的 Pillow 和 PIL 版本的错误。
我在这里找到了一个相关的帖子,Pyinstaller troubles with Pillow,但它的解决方案,即使用 py2app 而不是 pyinstaller 对我来说不是一个选项,因为它适用于 MacOS,我需要 Windows。我考虑为 windows、py2exe 和 cx_freeze 使用类似的替代方案,但它们不会像 pyinstaller 那样创建一个独立的 exe。
谢谢, 阿米特
【问题讨论】:
-
更新:我在这里发现了另一个可能相关的问题,需要详细了解并尝试一下:stackoverflow.com/questions/10453858/…
-
更新:py2exe 文档中的另一个可能线索:py2exe.org/index.cgi/py2exeAndPIL
-
欢迎来到 SO。提出一个奇妙的问题并在询问后进行研究的方式! +1。您的第二条评论中的链接是我刚要建议的 - 这是我在编译的应用程序中使用 PIL 的方法(我使用 py2exe,而不是 pyinstaller,但修复可能相同)。干得好,朋友。
-
谢谢,g.d.d.c :) 只是在学习我的方式,所以......多么棒的资源!我意识到我可能应该用两个更新来编辑我的帖子,而不是将它们添加为 cmets:P 是的,将尝试第二个选项并在此处更新...
标签: python python-imaging-library pyinstaller .emf