Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 无法运行简单的枕头示例(无法找到arial.pil)_Python 2.7_Drawing_Pillow - Fatal编程技术网

Python 2.7 无法运行简单的枕头示例(无法找到arial.pil)

Python 2.7 无法运行简单的枕头示例(无法找到arial.pil),python-2.7,drawing,pillow,Python 2.7,Drawing,Pillow,枕头是在Ubuntu14.04下使用pip安装枕头构建的: PIL SETUP SUMMARY -------------------------------------------------------------------- version Pillow 2.4.0 platform linux2 2.7.6 (default, Mar 22 2014, 22:59:38) [GCC 4.8.2] ---

枕头是在Ubuntu14.04下使用pip安装枕头构建的:

PIL SETUP SUMMARY
    --------------------------------------------------------------------
    version      Pillow 2.4.0
    platform     linux2 2.7.6 (default, Mar 22 2014, 22:59:38)
                 [GCC 4.8.2]
    --------------------------------------------------------------------
    *** TKINTER support not available
    (Tcl/Tk 8.6 libraries needed)
    --- JPEG support available
    *** OPENJPEG (JPEG2000) support not available
    --- ZLIB (PNG/ZIP) support available
    --- LIBTIFF support available
    --- FREETYPE2 support available
    --- LITTLECMS2 support available
    --- WEBP support available
    --- WEBPMUX support available
    --------------------------------------------------------------------
    To add a missing option, make sure you have the required
    library, and set the corresponding ROOT variable in the
    setup.py script.

    To check the build, run the selftest.py script.

    changing mode of build/scripts-2.7/pilfile.py from 644 to 755
    changing mode of build/scripts-2.7/pildriver.py from 644 to 755
    changing mode of build/scripts-2.7/pilconvert.py from 644 to 755
    changing mode of build/scripts-2.7/pilfont.py from 644 to 755
    changing mode of build/scripts-2.7/pilprint.py from 644 to 755
    changing mode of /usr/local/bin/pilfile.py to 755
    changing mode of /usr/local/bin/pildriver.py to 755
    changing mode of /usr/local/bin/pilconvert.py to 755
    changing mode of /usr/local/bin/pilfont.py to 755
    changing mode of /usr/local/bin/pilprint.py to 755
Successfully installed Pillow
Cleaning up...
但在运行以下示例时:

from PIL import ImageFont, ImageDraw

draw = ImageDraw.Draw(image)

# use a bitmap font
font = ImageFont.load("arial.pil")

draw.text((10, 10), "hello", font=font)

# use a truetype font
font = ImageFont.truetype("arial.ttf", 15)

draw.text((10, 25), "world", font=font)
代码找不到“arial.pil”

您正在使用此文件

首先,在同一目录中是否有名为
arial.pil
的文件?键入以下内容以了解:

ls arial.pil
你的电脑里有吗

locate arial.pil

可能不是,这只是示例代码。无论如何,您可能不想要
arial.pil
。(如果您这样做,请尝试。)相反,请将
arial.pil
替换为系统中字体的文件名(带路径)(例如,)。

arial.pil是一个文件,此错误很可能是因为您当前没有该文件。你可以试试Arial。代码如下所示:

font = ImageFont.truetype("Arial", 15)

文件arial.pil显然未安装。我认为当安装Pillow时,也会安装一些字体,比如arial.pil。最后,我写了这个:font=ImageFont.truetype(“/usr/share/fonts/truetype/freefont/FreeMono.ttf”,60)