I have a wxpython program where I keep the picture files in a zip file. Program runs fine while running by python. But when I run pyinstaller to produce exe file, I get IO error. Here is my program.
import zipfile
import wx
from PIL import Image
from StringIO import StringIO
def PilImageToWxImage(myPilImage):
myWxImage = wx.EmptyImage(myPilImage.size[0], myPilImage.size[1])
myWxImage.SetData(myPilImage.convert('RGB').tostring())
return myWxImage
class Frame1(wx.Frame):
def __init__(self, *args, **kwds):
wx.Frame.__init__(self, *args, **kwds)
z = zipfile.ZipFile("Data.zip", "r")
zl = z.namelist()
x = z.read(zl[0])
y = StringIO(x)
w = Image.open(y)
v = PilImageToWxImage(w).ConvertToBitmap()
u = wx.EmptyIcon()
u.CopyFromBitmap(v)
self.SetIcon(u)
if __name__ == "__main__":
a = wx.App(0)
f = Frame1(None, -1, "Test")
f.Show()
a.MainLoop()
This program runs ok when I run by python test.py
from command prompt. But when I run the test.exe file produced by pyinstaller --onefile --console --upx-dir='J:\Programs' test.py
, I get error :
Traceback (most recent call last):
File "<string>", line 26, in <module>
File "<string>", line 18, in __init__
File "J:\Programs\Python\PyInstaller\build\test\out00-PYZ.pyz\PIL.Image", line 2274, in open
IOError: cannot identify image file <StringIO.StringIO instance at 0x00000000048E1BC8>
I cannot figure what is wrong here. Please help.
Thanks.