简体   繁体   English

在Windows 7上的pil png activestate ZLIB(PNG / ZIP)支持不可用

[英]pil png activestate on windows 7 ZLIB (PNG/ZIP) support not available

I'm trying to port a python program from OS X to Windows 7. This program processes a png with tkinter eg 我正在尝试将一个python程序从OS X移植到Windows 7.该程序使用tkinter处理png,例如

self.logoImg = ImageTk.PhotoImage(Image.open('GrowthPathLogo.png'))

The code is failing with IOError: decoder zip not available 代码失败,IOError:解码器zip不可用

I've tried installing pip with pypm. 我尝试用pypm安装pip。 Then I try building it with pip. 然后我尝试用pip构建它。 At the end of the build process it reports that there is no support for png/zlib 在构建过程结束时,它报告不支持png / zlib

I get the same errors with the python.org installation on Windows. 我在Windows上安装了python.org时遇到了同样的错误。

I'm stuck and I'm not skilled at building C libraries. 我被困住了,我不擅长构建C库。 Neither do I know how pip works. 我也不知道pip是如何工作的。 I have a gnu zlib library installed but it's not helping at all. 我安装了一个gnu zlib库,但它根本没有帮助。 I have Visual C++ 2008 Express installed, and at least that's working because pip does compile things successfully. 我安装了Visual C ++ 2008 Express,至少可以正常工作,因为pip会成功编译。

Try the build here that's maintained by Christoph Gohlke. 尝试构建这里多数民众赞成由克里斯托夫Gohlke维护。 To build PIL yourself you need several libraries as mentioned in the README: libjpeg, zlib, freetype2, and littleCMS. 要自己构建PIL,您需要在README中提到的几个库:libjpeg,zlib,freetype2和littleCMS。 Read USAGE.txt in zlib125-dll.zip for instructions on linking to zlib with Visual C++ or MinGW. 请阅读zlib125-dll.zip中的USAGE.txt,以获取有关使用Visual C ++或MinGW链接到zlib的说明。

I know this is an old question, but I wanted to give my answer in case people run into the same problem as me. 我知道这是一个老问题,但我想给出答案,以防人们遇到与我相同的问题。

The builds by Christoph Gohlke are awesome, when they work. 当他们工作时,Christoph Gohlke的构建非常棒。 However for my win7 machine with python 2.7 and most importantly 64bit, there is no precompiled binary with PNG support (zlib support). 但是对于我的带有python 2.7和最重要的64位的win7机器,没有预编译的二进制文件支持PNG(zlib支持)。 The Pillow 64bit Binary on that page fails on easy_install and can't be installed on my machine. 该页面上的Pillow 64bit二进制文件在easy_install上失败,无法在我的机器上安装。

So if you want to solve this and the binary doesn't work you need to build Pillow your self with zlib support. 因此,如果你想解决这个并且二进制文件不起作用,你需要使用zlib支持来构建Pillow你的自我。 To do this you need to download the latest Pillow source. 为此,您需要下载最新的枕头来源。 Modify in setup.py the ZLIB_ROOT line to say: 在setup.py中修改ZLIB_ROOT行说:

ZLIB_ROOT = './zlib'

Now you have to build zlib for win64 bit as well, that's the tricky part. 现在你必须为win64位构建zlib,这是棘手的部分。 Download latest zlib source from their site (I tested on 1.2.5/1.2.8). 从他们的网站下载最新的zlib源代码(我在1.2.5 / 1.2.8上测试过)。 Open visual studio command prompt for 64 bit (VERY IMPORTANT) My command prompt was called VS2012 x64 Cross Tools Command Prompt. 打开64位的visual studio命令提示符(非常重要)我的命令提示符称为VS2012 x64交叉工具命令提示符。

Go to the zlib source dir and run: 转到zlib源目录并运行:

nmake -f win32/Makefile.msc

If it doesnt work try: 如果它不起作用尝试:

nmake -f win32/Makefile.msc AS=ml64 LOC="-DASMV -DASMINF" OBJA="inffasx64.obj gvmat64.obj inffas8664.obj"

Now you should have in the source directory the following files: 现在,您应该在源目录中包含以下文件:

zlib.h
zconf.h
zutil.h (not sure this is needed)
zlib.lib
zdll.lib

Copy them into the Pillow source directory, into a directory called "zlib" Compile Pillow using "python setup.py build_ext -i" Install Pillow using "python setup.py install" 将它们复制到枕头源目录,为使用名为“zlib的”编译枕头目录"python setup.py build_ext -i"枕头使用安装"python setup.py install"

Pillow should now work with ZLIB (png) support. 枕头现在应该与ZLIB(png)支持一起使用。 If you have some older Pillow/PIL installations, you might need to manually copy the _imaging.pyd and _imagingmath.pyd to the package installation folder of your python or virtual environment, to make sure you have the newly compiled ones. 如果您安装了一些较旧的Pillow / PIL,则可能需要手动将_imaging.pyd和_imagingmath.pyd复制到python或虚拟环境的软件包安装文件夹中,以确保您拥有新编译的软件包。

You can now import _imaging and you have png support. 您现在可以导入_imaging并获得png支持。

You can also add Libjpeg in the same way, compiling it manually, if needed. 您也可以以相同的方式添加Libjpeg,如果需要,可以手动编译它。

Hope this helps anyone that encounters this problem. 希望这有助于遇到此问题的任何人。

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

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