I have a peculiar problem at the intersection of the EMF image format, the python PIL (as well as Pillow) image libraries, and the Pyinstaller program for packaging Python into a Windows executable.
I have a script that uses PIL/Pillow to convert an EMF file to JPEG. This works correctly when I run the python script in python. However, when I package it into an EXE using Pyinstaller.exe -F, it does not work.
With the Pillow version, I get a simple error saying
"Cannot convert image1.emf".
With the PIL version, I get a longer message that says:
Traceback (most recent call last): File "", line 38, in File "", line 27, in convertImageFile File "C:\Embibe\Git\content-ingestion\src\build\convertImage\out00-PYZ.pyz\PIL .Image", line 2126, in open IOError: cannot identify image file 'image1.emf'
Has anyone else encountered this and found a working solution?
The gory details follow, if you need them... :-)
OS: Windows 7 64-bit (but all software is 32 bit)
Software:: Python:2.7.5, Pyinstaller:2.1, PIL:built-in with Python, Pillow: 2.4.0
Python script 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)
run as: convImg.py image1.emf
works correctly and generates image1.jpg.
When packaged to exe using \python27\scripts\pyinstaller.exe -F convImg.py
and run as convImg.exe image1
gives the errors listed above for the Pillow and PIL versions.
I found a related post here, Pyinstaller troubles with Pillow but the solution for it, namely using py2app instead of pyinstaller is not an option for me since that is for MacOS and I need Windows. I considered using similar alternatives for windows, py2exe and cx_freeze, but they do not create a single self-contained exe like pyinstaller does.
Thanks, Amit