DMC*_*ing 3 python python-imaging-library python-3.x docker alpine-linux
我正在尝试像这样导入和使用 python 枕头库:
from urllib.request import urlopen
import PIL
from PIL import Image, ImageFont, ImageDraw
import re
image = Image.open(urlopen("http://randomurl.com/randomimage.jpg"))
draw = ImageDraw.Draw(image)
font = ImageFont.truetype("sans-serif.ttf", 16)
draw.text((0, 0),"This is the future liberals want",(255,255,255),font=font)
image.save('sample-out.jpg')
Run Code Online (Sandbox Code Playgroud)
但是,我收到以下错误:
/opt/bot/app # python cli.py
Retrieving column Image ID on worksheet History
Traceback (most recent call last):
File "cli.py", line 38, in <module>
font = ImageFont.truetype("sans-serif.ttf", 16)
File "/usr/local/lib/python3.7/site-packages/PIL/ImageFont.py", line 260, in truetype
return FreeTypeFont(font, size, index, encoding, layout_engine)
File "/usr/local/lib/python3.7/site-packages/PIL/ImageFont.py", line 135, in __init__
if core.HAVE_RAQM:
File "/usr/local/lib/python3.7/site-packages/PIL/ImageFont.py", line 39, in __getattr__
raise ImportError("The _imagingft C module is not installed")
ImportError: The _imagingft C module is not installed
Run Code Online (Sandbox Code Playgroud)
我知道之前 StackOverflow 上也有人问过类似的问题。然而,所有答案似乎都涉及我不针对的执行环境。我在 docker 镜像中运行它python:3.7-rc-alpine3.7,现有的答案不起作用。以下是我安装的 pip 和 apk 包:http://dpaste.com/3EBW3A1
在Alpine平台上编译需要安装编译器(g++)、TrueType字体渲染库(freetype-dev)和加速基线JPEG压缩解压库(jpeg-dev) 。pillow
的部分Dockerfile是:
FROM python:3.7-rc-alpine3.7
RUN apk add --no-cache g++ freetype-dev jpeg-dev
RUN pip install pillow
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3129 次 |
| 最近记录: |