按照步骤操作如何安装 Python 图像库(PIL)?用于在 Ubuntu 14.04 上安装 PIL 的预安装库。但是当我运行时pip install PIL --allow-external PIL --allow-unverified PIL
看到以下错误:
building '_imagingft' extension
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/freetype2 -IlibImaging -I/usr/include -I/usr/include/tcl8.6 -I/usr/local/include -I/usr/include/python2.7 -c _imagingft.c -o build/temp.linux-x86_64-2.7/_imagingft.o
_imagingft.c:73:31: fatal error: freetype/fterrors.h: No such file or directory
#include <freetype/fterrors.h>
^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
----------------------------------------
Cleaning up...
Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_ubuntu/PIL/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-3ckD6N-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_ubuntu/PIL
Traceback (most recent call last):
File "/usr/local/bin/pip", line 9, in <module>
load_entry_point('pip==1.5.6', 'console_scripts', 'pip')()
File "/usr/local/lib/python2.7/dist-packages/pip-1.5.6-py2.7.egg/pip/__init__.py", line 185, in main
return command.main(cmd_args)
File "/usr/local/lib/python2.7/dist-packages/pip-1.5.6-py2.7.egg/pip/basecommand.py", line 161, in main
text = '\n'.join(complete_log)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 57: ordinal not in range(128)
答案1
我已使用以下命令成功安装了 PIL:
sudo apt-get build-dep python-imaging
sudo apt-get install libjpeg8 libjpeg62-dev libfreetype6 libfreetype6-dev
sudo pip install Pillow
执行完这些命令后我可以:
>>> import PIL
>>> PIL.VERSION
'1.1.7'
答案2
我在尝试安装 Pillow 2.0.0 时遇到了同样的错误。我在 [这里] 找到了解决方案。(https://github.com/collective/buildout.python/issues/39)
简而言之,freetype库的位置在14.04中移动了。权宜之计,即使修复不当,就是创建一个符号链接。在我的系统上,库不在,/usr
所以/usr/local
我这样做了:
ln -s /usr/include/freetype2 /usr/include/freetype
完成此操作后,我意识到我可以通过更新 Pillow 到 >=2.6.0 来解决这个问题。但无论如何,您的问题是安装 PIL,因此符号链接修复可能对您来说是一个不错的选择。