Reputation: 5975
I'm using the chemlab library for the first time. I'm trying to run some of the example programs but I keep getting the following error message:
import ImageFont # From PIL
ImportError: No module named ImageFont
Here is the code to one of the basic examples (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)
I've tried installing ImageFont, PIL and Pillow via pip (Pillow was the only one that actually installed) but no luck.
Upvotes: 2
Views: 5432
Reputation: 5783
Install PIL
:
pip install pillow
Correct import for ImageFont
is:
from PIL import ImageFont
Here is an example of 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)
Upvotes: 3