I am trying to run a Python script that calls PIL (via Pillow). The script works perfectly on my MacBook, but I want it to run on Windows as well. I get an error that "decoder zip not available" (see full output below). Searching the web led me to download zlib and reinstall Pillow (as described in this question). Unfortunately I get the same exact error.
My questions are:
How/where do I install zlib? I downloaded a zip file, couldn't find any direction on the zlib website nor elsewhere. I tried putting the unzipped zlib folder in the Python site-packages folder with Pillow.
Am I missing something else that would give the error message? I'm surprised how difficult installing Pillow is.
Using Windows 7, Python 2.7, currently have Pillow 2.7.0 installed from zip file from https://pypi.python.org/pypi/Pillow/2.7.0
The script: (Basically it should open an image in a window and allow the user to draw rectangles over the image).
import Tkinter as tk
from Tkinter import *
import tkMessageBox
from PIL import ImageTk, Image
import subprocess
crop_regions = []
path = "D:/Temp/OCR_test/K111PS_V5_2"
class ImageCanvas(Frame):
# This class creates a Tkinter canvas and displays the first video frame grab
def __init__(self, master):
Frame.__init__(self, master)
self.grid_rowconfigure(0, weight=1)
self.grid_columnconfigure(0, weight=1)
self.canvas = Canvas(self, width=720, height=480, bd=0, highlightthickness=0)
self.canvas.grid(row=0, column=0, sticky='nsew', padx=4, pady=4)
class ImgTk(tk.Tk):
# This function asks the user to select portions of the first video frame grab that contain data to OCR
# Coordinates of data field locations are saved as a global variable to be passed to the rest of the script
def __init__(self):
tk.Tk.__init__(self)
tkMessageBox.showinfo(
message="On the following image, draw rectangles over the desired fields: \nlatitude, longitude, date, time and other \nin that order. \nClose the image window when finished")
self.main = ImageCanvas(self)
self.main.grid(row=0, column=0, sticky='nsew')
self.c = self.main.canvas
self.currentImage = {}
self.load_imgfile(path + '/images/0029.png')
self.c.bind('<ButtonPress-1>', self.click_down)
self.c.bind('<B1-Motion>', self.click_drag)
self.c.bind('<ButtonRelease-1>', self.rectangles)
def load_imgfile(self, filename):
self.img = Image.open(filename)
self.currentImage['data'] = self.img
self.photo = ImageTk.PhotoImage(self.img)
self.c.xview_moveto(0)
self.c.yview_moveto(0)
self.c.create_image(0, 0, image=self.photo, anchor='nw', tags='img')
self.c.config(scrollregion=self.c.bbox('all'))
self.currentImage['photo'] = self.photo
self.title("Draw rectangles")
def click_down(self, event):
self.anchor = (event.widget.canvasx(event.x),
event.widget.canvasy(event.y))
self.item = None
def click_drag(self, event):
selected_box = self.anchor + (event.widget.canvasx(event.x), event.widget.canvasy(event.y))
if self.item is None:
self.item = event.widget.create_rectangle(selected_box, outline="red3", width=2.1)
else:
event.widget.coords(self.item, *selected_box)
def rectangles(self, event):
if self.item:
self.click_drag(event)
box = tuple((int(round(v)) for v in event.widget.coords(self.item)))
roi = self.currentImage['data'].crop(box) # region of interest
lat = roi.size[0], ':', roi.size[1], ':', box[0], ':', box[1]
lat = str(lat)
lat = lat.replace(',', '')
lat = lat.replace("'", '')
lat = lat.replace(' ', '')
global crop_regions
crop_regions.append(lat)
app = ImgTk()
app.mainloop()
Error message:
Traceback (most recent call last):
File "D:/Scripts/DaileyScripts/Python/OCR/PIL_test.py", line 81, in <module>
app = ImgTk()
File "D:/Scripts/DaileyScripts/Python/OCR/PIL_test.py", line 37, in __init__
self.load_imgfile(path + '/images/0029.png')
File "D:/Scripts/DaileyScripts/Python/OCR/PIL_test.py", line 47, in load_imgfile
self.photo = ImageTk.PhotoImage(self.img)
File "build\bdist.win-amd64\egg\PIL\ImageTk.py", line 115, in __init__
self.paste(image)
File "build\bdist.win-amd64\egg\PIL\ImageTk.py", line 165, in paste
im.load()
File "build\bdist.win-amd64\egg\PIL\ImageFile.py", line 200, in load
d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
File "build\bdist.win-amd64\egg\PIL\Image.py", line 417, in _getdecoder
raise IOError("decoder %s not available" % decoder_name)
IOError: decoder zip not available
The modules seem to work otherwise, i.e. I can call them without error.