ImportError: No module named ImageFont

ImportError: No module named ImageFont

我是第一次使用 chemlab 库。我正在尝试 运行 一些示例程序,但我不断收到以下错误消息:

import ImageFont # From PIL

ImportError: No module named ImageFont

这是其中一个基本示例 (https://github.com/chemlab/chemlab/blob/master/examples/nacl.py) 的代码:

from chemlab.core import Atom, Molecule, crystal
from chemlab.graphics import display_system

# Molecule templates
na = Molecule([Atom('Na', [0.0, 0.0, 0.0])])
cl = Molecule([Atom('Cl', [0.0, 0.0, 0.0])])

s = crystal([[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]], # Fractional Positions
            [na, cl], # Molecules
            225, # Space Group
            cellpar = [.54, .54, .54, 90, 90, 90], # unit cell parameters
            repetitions = [5, 5, 5]) # unit cell repetitions in each direction

display_system(s)

我试过通过 pip 安装 ImageFont、PIL 和 Pillow(Pillow 是唯一一个实际安装的)但没有成功。

安装PIL:

pip install pillow

ImageFont 的正确导入是:

from PIL import ImageFont

这里是ImageFont的例子:

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)