今晚学习python PIL模块,练习生成验证码时,运行代码,报错ImportError: The _imagingft C module is not installed。代码如下(来自PIL - 廖雪峰的官方网站):
import Image, ImageDraw, ImageFont, ImageFilter
import random
# 随机字母:
def rndChar():
return chr(random.randint(65, 90))
# 随机颜色1:
def rndColor():
return (random.randint(64, 255), random.randint(64, 255), random.randint(64, 255))
# 随机颜色2:
def rndColor2():
return (random.randint(32, 127), random.randint(32, 127), random.randint(32, 127))
# 240 x 60:
width = 60 * 4
height = 60
image = Image.new('RGB', (width, height), (255, 255, 255))
# 创建Font对象:
font = ImageFont.truetype('Arial.ttf', 36)
# 创建Draw对象:
draw = ImageDraw.Draw(image)
# 填充每个像素:

在学习Python PIL模块生成验证码时遇到ImportError: The _imagingft C module is not installed错误。尝试通过安装MinGW解决,但最终通过删除并重新安装编译好的PIL库(Pillow)成功解决问题。建议在Windows环境下使用预编译的Python库以避免编译问题。
最低0.47元/天 解锁文章
1315

被折叠的 条评论
为什么被折叠?



