0

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.

Community
  • 1
  • 1
Evan
  • 1,960
  • 4
  • 26
  • 54
  • Why are you using Pillow 2.7.0? I have Python 2.7.13 with Pillow 3.3.0 installed on a Windows 7 machine, with no zlib issues. Try using `pip install Pillow` from the command line to get the latest version and dependencies. – martineau Jan 12 '17 at 00:07
  • I tried using Pillow 2.7.0 because that was the only version I could find on the package index page that would install on my system (not sure why), and that version was the only one in zip format and ended up being the only way to get it to install at all. I tried `pip install Pillow` and got `Could not find a version that satisfies the requirement Pillow (from versions: ) No matching distribution found for Pillow` – Evan Jan 12 '17 at 00:16
  • Just tried reinstalling with Pillow 3.3.0 after martineau's comment and got `ValueError: zlib is required unless explicitly disabled` Maybe pip installs zlib? I just tried `pip install zlib` and got the same error as my last comment. – Evan Jan 12 '17 at 00:26
  • The [***Windows Installation***](https://pillow.readthedocs.io/en/latest/installation.html#windows-installation) section says "We provide Pillow binaries for Windows compiled for the matrix of supported Pythons in both 32 and 64-bit versions in wheel, egg, and executable installers. These binaries have all of the optional libraries included:" followed by `> pip install Pillow` example command-line command. Try getting a version of Pillow from [this part of pypi](https://pypi.python.org/pypi/Pillow). – martineau Jan 12 '17 at 00:27

1 Answers1

0

zlib is already there in the NDK.

i was having the same problem. i have a note 8(samsung). just go to GitHub and install zlib from there, after that you will be avaible to install pillow.

c0d3x27
  • 193
  • 2
  • 15