Python Beginner's image Library (PIL) under Mac

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.