问题描述

登录面板时出现的错误:

QQ截图20190625192243.png

验证码图片失效了,导致不能正常登录。

当前环境

  • 面板版本:5.9.1
  • 树莓派系统:Ubuntu Mate 18.04.2 LTS 64位



产生原因

查看面板日志/tmp/panelBoot.pl发现有错误:


Traceback (most recent call last):
 File "/usr/local/lib/python2.7/dist-packages/web/application.py", line 239, in process
  return self.handle()
 File "/usr/local/lib/python2.7/dist-packages/web/application.py", line 230, in handle
  return self._delegate(fn, self.fvars, args)
 File "/usr/local/lib/python2.7/dist-packages/web/application.py", line 462, in _delegate
  return handle_class(cls)
 File "/usr/local/lib/python2.7/dist-packages/web/application.py", line 438, in handle_class
  return tocall(*args)
 File "main.py", line 488, in GET
  codeImage = vie.GetCodeImage(80,4);
 File "/www/server/panel/class/vilidate.py", line 42, in GetCodeImage
  self.__createNoise()
 File "/www/server/panel/class/vilidate.py", line 80, in __createNoise
  font = ImageFont.truetype(self.__fontPatn, int(self.__fontSize / 1.5))
 File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 218, in truetype
  return FreeTypeFont(filename, size, index, encoding)
 File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 134, in _init_
  self.font = core.getfont(file, size, index, encoding)
 File "/usr/local/lib/python2.7/dist-packages/PIL/ImageFont.py", line 34, in _getattr_
  raise ImportError("The _imagingft C module is not installed")
ImportError: The _imagingft C module is not installed

查阅资料发现是PIL没有加入freetype支持库来编译而导致的问题,即/usr/local/lib/python2.7/dist-packages/PIL目录下没有_imagingft.so文件,重新编译PIL可解决。




解决方法

编译 PIL(Imaging) 之前需要安装 JPEGfreetypezlib 支持库。

JPEG库编译和安装

cd ~/
wget http://www.ijg.org/files/jpegsrc.v9c.tar.gz
tar xvf jpegsrc.v9c.tar.gz
cd jpeg-9c
./configure
sudo make
sudo make install

freetype库编译和安装

cd ~/
wget https://download.savannah.gnu.org/releases/freetype/freetype-2.10.0.tar.gz
tar xvf freetype-2.10.0.tar.gz
cd freetype-2.10.0
./configure
sudo make
sudo make install

zlib库编译和安装

cd ~/
wget http://www.zlib.net/zlib-1.2.11.tar.gz
tar xvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
sudo make
sudo make install

PIL编译和安装

编译PIL前需要指定支持库的路径,首先下载源代码解压。

wget http://effbot.org/media/downloads/Imaging-1.1.7.tar.gz
tar xvf Imaging-1.1.7.tar.gz

进入目录修改setup.py文件。

cd Imaging-1.1.7
sudo nano setup.py

TCL_ROOT = None
JPEG_ROOT = None
ZLIB_ROOT = None
TIFF_ROOT = None
FREETYPE_ROOT = None
LCMS_ROOT = None

改为

TCL_ROOT = None
JPEG_ROOT = libinclude("/usr/local")
ZLIB_ROOT = libinclude("/usr/local")
TIFF_ROOT = None
FREETYPE_ROOT = '/usr/lib', '/usr/local/include/freetype2'
LCMS_ROOT = None

保存退出。
查看支持库路径是否指定成功。

sudo python setup.py build_ext

JPEGZLIB (PNG/ZIP)FREETYPE2都为support available则可以开始编译安装。先停止面板并卸载原来的Pillow。

sudo /etc/init.d/bt stop
sudo pip uninstall Pillow
sudo python setup.py install

编译安装完成后,启动宝塔面板即可。

sudo /etc/init.d/bt start

登录面板发现验证码图片能正常显示了。

QQ截图20190625202122.png