use*_*144 70 python image python-imaging-library
我已经尝试了很多在网上发布的解决方案,它们不起作用.
>>> import _imaging
>>> _imaging.__file__
'C:\\python26\\lib\\site-packages\\PIL\\_imaging.pyd'
>>>
Run Code Online (Sandbox Code Playgroud)
所以系统可以找到_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)
Run Code Online (Sandbox Code Playgroud)
引发此错误:
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")
Run Code Online (Sandbox Code Playgroud)
Sin*_*ren 75
在Ubuntu上,您需要在编译PIL之前安装libfreetype-dev.
即
$ sudo apt-get install libfreetype6-dev
$ sudo -s
\# pip uninstall pil
\# pip install pil
Run Code Online (Sandbox Code Playgroud)
PS!运行pip install作为sudo通常会在大多数Ubuntu版本上将软件包安装到/ usr/local/lib.您可以考虑在用户拥有的路径中将Pil安装在虚拟环境(virtualenv或venv)中.
您也可以考虑安装枕头而不是pil,我认为它与API兼容:https://python-pillow.org.
Imr*_*ran 56
您安装的PIL是在没有libfreetype的情况下编译的.
您可以在这里获得PIL的预编译安装程序(使用libfreetype编译)(以及许多其他预编译的Python C模块):
http://www.lfd.uci.edu/~gohlke/pythonlibs/
Raf*_*fay 42
以下在Ubuntu 14.04.1 64位上为我工作:
sudo apt-get install libfreetype6-dev
Run Code Online (Sandbox Code Playgroud)
然后,在virtualenv:
pip uninstall pillow
pip install --no-cache-dir pillow
Run Code Online (Sandbox Code Playgroud)
fsw*_*fsw 16
CentOS 6的解决方案(可能还有其他基于rpm的):
yum install freetype-devel libjpeg-devel libpng-devel
pip uninstall pil Pillow
pip install pil Pillow
Run Code Online (Sandbox Code Playgroud)
suz*_*kya 14
在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
Run Code Online (Sandbox Code Playgroud)
Ros*_*mbo 12
基本上,您需要在安装PIL之前安装freetype.
如果你在OS X上使用Homebrew,那只需要:
brew remove pil
brew install freetype
brew install pil
Run Code Online (Sandbox Code Playgroud)
Dmi*_*lov 12
为Ubuntu 12.10工作:
sudo pip uninstall PIL
sudo apt-get install libfreetype6-dev
sudo apt-get install python-imaging
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
70230 次 |
| 最近记录: |