MAC 下安裝PIL


1. 安裝使用

pip install pil

結果報如下錯誤

Collecting PIL
  Could not find a version that satisfies the requirement PIL (from versions: )
  Some externally hosted files were ignored as access to them may be unreliable (use --allow-external PIL to allow).
No matching distribution found for PIL

2. 

This is due to changes in the new version of Pip. Run pip --version and I'm willing to bet you are running 1.5. See the changelog here. This new default behavior enhances security. In PIL's case, the file you are installing actually comes from effbot.org (thus --allow-external) and PyPi doesn't have a checksum to guarantee validity (thus --allow-unverified).

Also, you might consider using the Pillow replacement to PIL.

pip install PIL --allow-external PIL --allow-unverified PIL

報如下錯誤 :

 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/tk.h:78:11: fatal error: 'X11/Xlib.h' file not found
  #       include <X11/Xlib.h>
                  ^
  1 error generated.
  error: command 'cc' failed with exit status 1
  
  ----------------------------------------
  Failed building wheel for PIL
Failed to build PIL

3. 

sudo ln -s  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.pl
atform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers/X11 /
usr/local/include/X11

再次執行:

pip install PIL --allow-external PIL --allow-unverified PIL

又報錯誤 :

    100% |████████████████████████████████| 507kB 97kB/s 
Building wheels for collected packages: PIL
  Running setup.py bdist_wheel for PIL
  Stored in directory: /Users/zhangxin/Library/Caches/pip/wheels/ba/31/4a/9a5596f0640c9099a4302a71b56b7581e16e0d0b5a8f30ce3e
Successfully built PIL
Installing collected packages: PIL
Exception:
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/pip/basecommand.py", line 211, in main
    status = self.run(options, args)
  File "/Library/Python/2.7/site-packages/pip/commands/install.py", line 311, in run
    root=options.root_path,
  File "/Library/Python/2.7/site-packages/pip/req/req_set.py", line 646, in install
    **kwargs
  File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 803, in install
    self.move_wheel_files(self.source_dir, root=root)
  File "/Library/Python/2.7/site-packages/pip/req/req_install.py", line 998, in move_wheel_files
    isolated=self.isolated,
  File "/Library/Python/2.7/site-packages/pip/wheel.py", line 339, in move_wheel_files
    clobber(source, lib_dir, True)
  File "/Library/Python/2.7/site-packages/pip/wheel.py", line 317, in clobber
    shutil.copyfile(srcfile, destfile)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 83, in copyfile
    with open(dst, 'wb') as fdst:
IOError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/PIL.pth'

這次是忘了加sudo,加上就OK了。

localhost:newlabel zhangxin$ sudo pip install PIL --allow-external PIL --allow-unverified PIL
Password:
The directory '/Users/zhangxin/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/zhangxin/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting PIL
/Library/Python/2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  PIL is potentially insecure and unverifiable.
Installing collected packages: PIL
Successfully installed PIL-1.1.7

 

 

 

 

4. 在使用ImageFont.truetype(fontname, 36)時又出現錯誤:

Traceback (most recent call last):
  File "generate.py", line 40, in <module>
    font = ImageFont.truetype(fontname, 36)
  File "/Library/Python/2.7/site-packages/PIL/ImageFont.py", line 218, in truetype
    return FreeTypeFont(filename, size, index, encoding)
  File "/Library/Python/2.7/site-packages/PIL/ImageFont.py", line 134, in __init__
    self.font = core.getfont(file, size, index, encoding)
  File "/Library/Python/2.7/site-packages/PIL/ImageFont.py", line 34, in __getattr__
    raise ImportError("The _imagingft C module is not installed")
ImportError: The _imagingft C module is not installed
View Code

 

5. 后來,我改變主意了,我卸載了pil,我安裝pillow。

sudo pip install pillow

然后成功了。叫我神經病吧

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM