您的位置:首页 > 其它

MAC 下安装PIL

2015-09-09 17:31 337 查看
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


然后成功了。叫我神经病吧
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: