python - 导入错误:没有名为 ImageFont 的模块

标签 python importerror

我是第一次使用 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)

关于python - 导入错误:没有名为 ImageFont 的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39928682/

相关文章:

python - 无法在 python 3 中导入 matplotlib.pyplot

python - 如何摆脱 Perl 和 Python [两者] 中的非 ascii 字符?

python - 如何跨 swig 类型映射重用代码?

python - 使用python从csv文件中读取复数

python - 如何浏览到带有绘图破折号的文件夹?

python - 在 Python 和 IronPython 之间传递 pickle

python - cx_freeze 执行文件时出现导入错误

Python:从已导入的模块导入函数

python - AppEngine 映射器 API 导入错误