Mac under Python using Image Library
Install PIL, download http://www.pythonware.com/products/pil/
Unzip the PIL source package, read the Readme know the need to use the python setup.py Install command to compile the installation.
Of course, the first time is usually not passed, generally some library files can not be found, such as X11lib.
Modify setup.py:
1, 36 lines onwards
Tcl_root = None
jpeg_root = JPEG Library Directory
Zlib_root = PNG and ZLIB library directories
Tiff_root = TIFF Library Directory
Freetype_root = FREETYPE Library Directory
Lcms_root = None
The focus here is the catalog of JPEG and zlib libraries.
A) zlib
Most of the development libraries under Mac are not in the USR directory, if you have Xcode installed, then:
Zlib_root = Libinclude ("/applications/xcode.app/contents/developer/platforms/macosx.platform/developer/sdks/ Macosx10.9.sdk/usr ")
Otherwise you will need to install the appropriate zlib library, and then add your directory path.
b) Jpeg
The JPEG library needs to install itself, after downloading the JPEG resource bundle, unzip into execution ./configure The makefile, then sudomake install will be installed in/usr/local/ lib download.
Then add the path to PiL's setup.py:
Jpeg_root = "/usr/local/lib"
2, about 210 rows or so
add_directory (Library_dirs, "/usr/local/ Lib ")
add_directory (Include_dirs,"/usr/local/include ")
add_directory (Library_dirs, "/usr/lib")
add_directory (Include_dirs, "/ Usr/include ")
To add a related library directory:
add_directory (library_dirs, "/applications/xcode.app/contents/developer/platforms/macosx.platform/developer /sdks/macosx10.9.sdk/usr/lib ")
Add_directory (Include_dirs, "/applications/xcode.app/contents/developer/platforms/macosx.platform/developer/ Sdks/macosx10.9.sdk/system/library/frameworks/tk.framework/versions/8.5/headers ")
Add_directory (Include_dirs, "/applications/xcode.app/contents/developer/platforms/macosx.platform/developer/ Sdks/macosx10.9.sdk/usr/include ")
And then compile the installation.
In addition, if PNG and JPEG library directories are not set, PIL can be installed successfully but the decoder will not be found during use. To determine whether PNG and JPEG are supported, use the following methods:
Python selftest.py
If you see
---JPEG support OK
---ZLIB (png/zip) Support OK
Indicates that the two libraries are configured correctly.
Finally, a simple test.py script can be written to test:
Import Image
im = Image.open ("/Do not write ~ path/desktop/y.jpg")
Im.save ("/Do not write ~ path/desktop/x.jpg")
Python Beginner's image Library (PIL) under Mac