简体   繁体   English

如何在Windows上为Python 2.7 Pillow安装zlib?

[英]How do I install zlib for Python 2.7 Pillow on Windows?

I am trying to run a Python script that calls PIL (via Pillow). 我正在尝试运行一个调用PIL的Python脚本(通过Pillow)。 The script works perfectly on my MacBook, but I want it to run on Windows as well. 该脚本可以在我的MacBook上完美运行,但是我也希望它也可以在Windows上运行。 I get an error that "decoder zip not available" (see full output below). 我收到一个错误消息“解码器zip不可用”(请参阅​​下面的完整输出)。 Searching the web led me to download zlib and reinstall Pillow (as described in this question ). 在网上搜索后,我下载了zlib并重新安装了Pillow(如本问题所述 )。 Unfortunately I get the same exact error. 不幸的是,我得到同样的错误。

My questions are: 我的问题是:
How/where do I install zlib? 如何/在哪里安装zlib? I downloaded a zip file, couldn't find any direction on the zlib website nor elsewhere. 我下载了一个zip文件,在zlib网站或其他任何地方都找不到任何方向。 I tried putting the unzipped zlib folder in the Python site-packages folder with Pillow. 我尝试使用Pillow将解压缩的zlib文件夹放入Python site-packages文件夹中。

Am I missing something else that would give the error message? 我是否还缺少其他一些会给出错误消息的信息? I'm surprised how difficult installing Pillow is. 我很惊讶安装Pillow有多么困难。

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 使用Windows 7,Python 2.7当前已从https://pypi.python.org/pypi/Pillow/2.7.0的 zip文件安装了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, ie I can call them without error. 这些模块似乎可以正常工作,也就是说,我可以毫无错误地调用它们。

zlib is already there in the NDK. NDK中已经存在 zlib。

i was having the same problem. 我有同样的问题。 i have a note 8(samsung). 我有一个音符8(三星)。 just go to GitHub and install zlib from there, after that you will be avaible to install pillow. 只需转到GitHub并从那里安装zlib,之后您就可以安装枕头了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM