未分类
centos下安装pillow报ImportError: The _imagingft C module is not installed的解决方案
django运行opsmanage项目报错:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
68,1 Bot return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 680, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 790, in exec_module File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "/data/OpsManage/apps/api/urls.py", line 2, in <module> from api.views import (assets_api,deploy_api,mysql_api, File "/data/OpsManage/apps/api/views/nav_api.py", line 12, in <module> from dao.navbar import NAVBAR File "/data/OpsManage/dao/navbar.py", line 7, in <module> from utils.avatar import AVATAR File "/data/OpsManage/utils/avatar.py", line 55, in <module> AVATAR = Avatar() File "/data/OpsManage/utils/avatar.py", line 17, in __init__ self.font = ImageFont.truetype(os.getcwd() + '/static/font-awesome/fonts/NotoSansCJKsc-Regular.otf', self.font_size) File "/root/.python_env/.virtualenvs/ops/lib/python3.9/site-packages/PIL/ImageFont.py", line 260, in truetype return FreeTypeFont(font, size, index, encoding, layout_engine) File "/root/.python_env/.virtualenvs/ops/lib/python3.9/site-packages/PIL/ImageFont.py", line 135, in __init__ if core.HAVE_RAQM: File "/root/.python_env/.virtualenvs/ops/lib/python3.9/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 |
解决: centos系统,使用pip安装pillow,运行时出现ImportError错误“The _imagingft C module is not installed” 具体出错的那行代码是font = ImageFont.truetype(‘Arial.ttf’, 36) 解决过程如下: 先确保代码中导入语句是:
1 |
from PIL import ImageFont |
尝试先卸载pillow:
1 |
pip uninstall pillow |
安装系统devel包:
1 |
sudo yum install libtiff-devel libjpeg-devel libzip-devel freetype-devel lcms2-devel libwebp-devel tcl-devel tk-devel |
再重新安装pillow:
1 |
pip install pillow |
安装完毕。但运行时仍然报错,试了几次仍然不行。 最后在安装pillow时,加上 –no-cache-dir参数:
1 |
pip install pillow --no-cache-dir |
再试,成功。 另外, 安装daphne失败:
1 2 |
ERROR: Could not find a version that satisfies the requirement twisted>=18.7 (from daphne==2.2.2->-r requirements.txt (line 22)) (from versions: none) ERROR: No matching distribution found for twisted>=18.7 (from daphne==2.2.2->-r requirements.txt (line 22)) |
可以用以下安装:
1 |
pip install https://github.com/twisted/twisted/archive/twisted-18.7.0.zip |