CentOS7.6+Python3.8.8下_imagingft C模块导入失败求助
解决CentOS 7.6下Python 3.8.8环境PIL _imagingft模块导入失败问题
1. 补全系统依赖库
CentOS 7.6默认缺少freetype等编译依赖,先安装完整开发包:
yum install -y freetype-devel libraqm-devel libjpeg-devel zlib-devel
2. 检查_imagingft.so的动态依赖
用ldd命令验证该文件是否存在缺失的系统库:
ldd /root/.cache/pypoetry/virtualenvs/py-plugin-FB7jtJE--py3.8/lib/python3.8/site-packages/PIL/_imagingft.so
若输出中出现not found项,对应安装缺失的库包后重新编译PIL。
3. 强制重新编译安装Pillow(指定系统库路径)
先卸载当前环境的Pillow:
poetry remove pillow
再手动指定freetype和raqm的系统路径重新安装,确保编译时正确链接:
poetry add pillow --install-option="--freetype-dir=/usr/lib64" --install-option="--raqm-dir=/usr/lib64"
若/usr/lib64不是freetype实际路径,用find / -name libfreetype.so查找后替换。
4. 重建虚拟环境
若虚拟环境存在路径混乱问题,直接删除重建:
rm -rf /root/.cache/pypoetry/virtualenvs/py-plugin-FB7jtJE--py3.8 poetry install
5. 验证Python编译时的freetype支持
重新编译Python时需明确指定freetype路径:
./configure --enable-optimizations --with-freetype-dir=/usr/lib64 make && make install
编译完成后验证支持状态:
python3.8 -c "from PIL import features; print(features.check('freetype'))"
输出True则说明freetype支持已启用,否则需重新编译并确保依赖安装完整。
内容的提问来源于stack exchange,提问作者realhuhu
相关产品推荐
相关产品推荐

