[Python] Problems with installing PIL under Windows __python

Source: Internet
Author: User
Tags win32 python script theano
The following is the difficult process of installation PIL, encountered some problems halfway, although many similar problems on the Internet solution, can be the same only tell very simple "how to deal with" on it, but I just can not complete this step.
Let me first introduce my environment at the end of the finish, Windows 7 64-bit system, Python 2.7.9 32-bit, and pillow-2.7.0.win32-py2.7.
First of all, rookie learning PiL, directly according to Liaoche Teacher's Python tutorial on the method to install PIL ("Windows platform to pil the official website download EXE package")
Then, according to his template wrote a very simple code to generate the image of the small program, a series of problems ensued.
1. The line of code that appears importerror error "The _IMAGINGFT C module is isn't installed" is font = Imagefont.truetype (' Arial.ttf ', 36), which comments the line After that, you can run it correctly, except that the verification code on the picture is the default font and size and is not visible at all.
Everyone's proposal is PIL official compilation package has bugs, it is best to download a third-party organization compiled package, strongly recommend pillow, and then I am in a famous unofficial website (http://www.lfd.uci.edu/~gohlke/pythonlibs/ ) Pillow on the load. The Web site offers only one of the available downloads for Windows: PILLOW-2.7.0-CP26-NONE-WIN32.WHL
Pillow-2.7.0-cp26-none-win_amd64.whl
Pillow-2.7.0-cp27-none-win32.whl
Pillow-2.7.0-cp27-none-win_amd64.whl
Pillow-2.7.0-cp32-none-win32.whl
Pillow-2.7.0-cp32-none-win_amd64.whl
Pillow-2.7.0-cp33-none-win32.whl
Pillow-2.7.0-cp33-none-win_amd64.whl
Pillow-2.7.0-cp34-none-win32.whl
Pillow-2.7.0-cp34-none-win_amd64.whl
Pillow-2.7.0.win32-pypy2.4-py2.7.zip
2. Download the compressed package has two folders bin and site-packages, the problem again, for a small white, this How to install is good. There are also PIL and Pillow-2.7.0-py2.7.egg-info under the Site-packages folder, which should be the Third-party library files that appear in the Python27/lib/site-packages folder after the EXE is installed. Python is green anyway, so just copy the two folders to the directory.
There is no previous error, but there is still a mistake. "Importerror:cannot Import name _imaging".
So, I guess, it's about what's in the bin directory. Where to put the five. py files (pilconvert.py, pildriver.py, pilfile.py, pilfont.py, pilprint.py) under the directory.
3. Then look at Pillow's documentation for installation issues, and the documentation gives you the following two ways to install Windows:
Windows Installation
We provide binaries for Windows in the form of Python Eggs and Python wheels:

Python Eggs
PIP does not support Python Eggs; Use Easy_install instead.
$ easy_install Pillow

Python Wheels
Experimental. Requires setuptools >=0.8 and Pip >=1.4.1
$ pip Install--use-wheel Pillow


If the above does not work, it's likely because we haven ' t uploaded a wheel for the latest version of Pillow. In the case, try pinning it to a specific version:
$ pip Install--use-wheel pillow==2.6.1
I installed it in a easy_install way, but the result was installed in the Theano (originally installed when churn deep learning, did not run through the Python and registry to make a pulpy) directory, My computer was loaded with 32 and 64-bit python2.7.4 versions, and the Python directory in the environment variable was modified to Theano. It was too messy, so I chose to uninstall all the Python and third-party libraries directly, then reinstall Python, and install Easy_install, otherwise the command prompt above is not an internal command.
4. Finally, I am too lazy to install easy_install, finally found the Pillow EXE version (https://pypi.python.org/pypi/Pillow/2.7.0), directly double-click the installation is very convenient. After installing it, be sure to note that import image must be replaced by From pil import ImageOne more thing to note is that if you first install the official PIL, you need uninstall PIL First and then install Pillow, and to ensure that the unloading of the site-packages in the PiL file deleted, otherwise installed pillow PiL will be with the previous PIL merged, resulting in some unexpected errors.
To summarize the issues that need to be noted: (1) determine if the version of Python is consistent with the version of the Third-party library that you want to install and the Python version it supports, which is consistent, in addition to the version number, to 32 digits or 64 digits, Sometimes 32-bit Third-party libraries are not installed on 64-bit python. (2) The official PIL has some bugs that can be replaced with pillow. If you install the official PIL first, you need to uninstall the PIL before installing the pillow. (3) Install pillow, use Easy_install or PIP installation must pay attention to the installation of the directory is not we are using this python. (The average person should not be like me so stupid to install so many versions of Python, anyway, my computer three windows, each system has python, there are several Python system) (4) Install pillow, strongly recommend to https:// pypi.python.org/pypi/pillow/2.7.0 Download the appropriate Pillow version of the EXE for installation. (5) When writing the Python script application image, import image must be replaced with the from PIL import image
Not easy to install the environment, followed by Liao Teacher Learning Python, the first Small code generation program:
#!/usr/bin/env python #-*-coding:utf-8-*-from PIL import Image, Imagedraw, Imagefont, Imagefilte R Import Random # random character def Rndchar (): Return Chr (Random.randint ()) # random color 1 def rndcolor () : Return (Random.randint, 255), Random.randint (255), Random.randint (255)) # random color 2 def rndColor2 ()  : Return (Random.randint, 127), Random.randint (127), Random.randint (M, 127)) # The width = 4 height = The image = Image.new (' RGB ', (width, height), (255, 255, 255)) # Create Font Object font = Imagefont.truetype (' Arial.tt F ', +] # Create Draw Object Draw = Imagedraw.draw (image) # Fill in every pixel to X in range (width): for y in rang  E (height): Draw.point ((x, y), fill = Rndcolor ()) # Output The text for T in range (4): draw.text (* t + 10, Rndchar (), font = font, fill = RndColor2 ()) # Fuzzy image = Image.filter (imagefilter.blur) image.save (' Code.jpg ', ' j Peg ') 


Reference: Http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/ 00140767171357714f87a053a824ffd811d98a83b58ec13000 http://www.lfd.uci.edu/~gohlke/pythonlibs/https:// pypi.python.org/pypi/pillow/2.7.0 http://pillow.readthedocs.org/en/latest/installation.html
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.