Python:未安装 _imagingft C 模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4011705/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python: The _imagingft C module is not installed
提问by user483144
I've tried lots of solution that posted on the net, they don't work.
我已经尝试了很多发布在网上的解决方案,它们都不起作用。
>>> import _imaging
>>> _imaging.__file__
'C:\python26\lib\site-packages\PIL\_imaging.pyd'
>>>
So the system can find the _imaging but still can't use truetype font
所以系统可以找到_imaging但仍然不能使用truetype字体
from PIL import Image, ImageDraw, ImageFilter, ImageFont
im = Image.new('RGB', (300,300), 'white')
draw = ImageDraw.Draw(im)
font = ImageFont.truetype('arial.ttf', 14)
draw.text((100,100), 'test text', font = font)
Raises this error:
引发此错误:
ImportError: The _imagingft C module is not installed
File "D:\Python26\Lib\site-packages\PIL\ImageFont.py", line 34, in __getattr__
raise ImportError("The _imagingft C module is not installed")
采纳答案by Imran
Your installed PIL was compiled without libfreetype.
您安装的 PIL 是在没有 libfreetype 的情况下编译的。
You can get precompiled installer of PIL (compiled with libfreetype) here (and many other precompiled Python C Modules):
您可以在此处获取 PIL 的预编译安装程序(使用 libfreetype 编译)(以及许多其他预编译 Python C 模块):
回答by Sindre Myren
On Ubuntu, you need to have libfreetype-dev installed before compiling PIL.
在 Ubuntu 上,你需要在编译 PIL 之前安装 libfreetype-dev。
i.e.
IE
$ sudo apt-get install libfreetype6-dev
$ sudo -s
\# pip uninstall pil
\# pip install pil
PS! Running pip install as sudo will usually install packages to /usr/local/lib on most Ubuntu versions. You may consider to install Pil in a virtual environment (virtualenv or venv) in a path owned by the user instead.
附注!在大多数 Ubuntu 版本上,以 sudo 的身份运行 pip install 通常会将软件包安装到 /usr/local/lib 。您可以考虑将 Pil 安装在用户拥有的路径中的虚拟环境(virtualenv 或 venv)中。
You may also consider installing pillow instead of pil, which I believe is API compatible: https://python-pillow.org.
您也可以考虑安装枕头而不是 pil,我认为它与 API 兼容:https: //python-pillow.org。
回答by milton
Ubuntu 11.10 installs zlib and freetype2 libraries following the multi-arch spec (e.g. /usr/lib/i386-linux-gnu). You may use PIL setup environment variables so it can find them. However it only works on PIL versions beyond the pil-117 tag.
Ubuntu 11.10 按照多架构规范(例如/usr/lib/i386-linux-gnu)安装 zlib 和 freetype2 库。您可以使用 PIL 设置环境变量,以便它可以找到它们。但是,它仅适用于 pil-117 标签之外的 PIL 版本。
export PIL_SETUP_ZLIB_ROOT=/usr/lib/i386-linux-gnu
export PIL_SETUP_FREETYPE_ROOT=/usr/lib/i386-linux-gnu
pip install -U PIL
Since your multi-arch path may be different (x86-64), it's preferable to install the -devpackages and use pkg-configto retrieve the correct path.
由于您的多架构路径可能不同 (x86-64),因此最好安装-dev软件包并用于pkg-config检索正确的路径。
pkg-config --variable=libdir zlib
pkg-config --variable=libdir freetype2
Another way given by Barry on Pillow's setup.py is to use dpkg-architecture -qDEB_HOST_MULTIARCHto obtain the proper library directory suffix.
Barry 在 Pillow 的 setup.py 上给出的另一种方法是使用dpkg-architecture -qDEB_HOST_MULTIARCH获取正确的库目录后缀。
回答by Bovard
回答by suzanshakya
In OS X, I did this to solve the problem:
在 OS X 中,我这样做是为了解决问题:
pip uninstall PIL
ln -s /usr/X11/include/freetype2 /usr/local/include/
ln -s /usr/X11/include/ft2build.h /usr/local/include/
ln -s /usr/X11/lib/libfreetype.6.dylib /usr/local/lib/
ln -s /usr/X11/lib/libfreetype.6.dylib /usr/local/lib/libfreetype.dylib
pip install PIL
回答by Roshambo
回答by DmitrySandalov
Worked for Ubuntu 12.10:
适用于 Ubuntu 12.10:
sudo pip uninstall PIL
sudo apt-get install libfreetype6-dev
sudo apt-get install python-imaging
回答by fsw
solution for CentOS 6 (and probably other rpm based):
CentOS 6 的解决方案(可能还有其他基于 rpm 的):
yum install freetype-devel libjpeg-devel libpng-devel
pip uninstall pil Pillow
pip install pil Pillow
回答by Jason Huang
The followed works on ubuntu 12.04:
以下在 ubuntu 12.04 上工作:
pip uninstall PIL
apt-get install libjpeg-dev
apt-get install libfreetype6-dev
apt-get install zlib1g-dev
apt-get install libpng12-dev
pip install PIL --upgrade
when your see "-- JPEG support avaliable" that means it works.
当您看到“-- JPEG 支持可用”时,这意味着它可以工作。
But, if it still doesn't work when your edit your jpeg image, check the python path!!
My python path missed '/usr/local/lib/python2.7/dist-packages/PIL-1.1.7-py2.7-linux-x86_64.egg/', so I edit the ~/.bashrcadd the following code to this file:
但是,如果在编辑 jpeg 图像时它仍然不起作用,请检查 python 路径!!
我的 python 路径丢失'/usr/local/lib/python2.7/dist-packages/PIL-1.1.7-py2.7-linux-x86_64.egg/',所以我编辑~/.bashrc添加以下代码到这个文件:
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/dist-packages/PIL-1.1.7-py2.7-linux-x86_64.egg/
then, finally, it works!!
然后,终于,它起作用了!!
回答by tc_geophysics
I used homebrew to install freetype and I have the following in /usr/local/lib:
我使用自制软件来安装 freetype,我在 /usr/local/lib 中有以下内容:
libfreetype.6.dylib libfreetype.a libfreetype.dylib
libfreetype.6.dylib libfreetype.a libfreetype.dylib
But the usual:
但通常的:
pip install pil
pip 安装 pil
Does not work for me, so I used:
对我不起作用,所以我使用了:
pip install http://effbot.org/downloads/Imaging-1.1.6.tar.gz

