前言

今天在服务器搭建一个Python项目,使用pip install -r requirements.txt以后宝塔面板直接炸了。

故障排查

  • 闯了祸的requirements.txt
    APScheduler==3.2.0
    werkzeug==0.11.15
    Flask==0.12
    requests==2.20.0
    lxml==3.7.2
    PyExecJS==1.5.1
    click==7.0
    gunicorn==19.9.0
    pymongo
    redis

全部写死版本,好像把系统里比较新的库卸掉换成旧版了。

  • 尝试重启面板
    输入/etc/init.d/bt 3,貌似Python依赖库有问题。

  • 宝塔面板修复工具
    输入/etc/init.d/bt 16,修复完还是不行,貌似解决不了依赖问题。

  • 手动修复依赖
    位置:/www/server/panel/requirements.txt
    内容:

    Flask>=1.0.2
    paramiko>=2.6.0
    flask-socketio>=4.1.0
    python-socketio>=4.2.0
    Werkzeug>=0.15.1
    Pillow==5.4.1
    requests>=2.20
    cffi>=1.12.3
    psutil>=5.2.0
    chardet>=3.0.4
    Flask-Session>=0.3.1
    flask-sqlalchemy>=2.3.2
    gunicorn>=18.0
    gevent-websocket>=0.10.1
    pyopenssl>=19.0
    cryptography>=2.7
    six>=1.12.0

    直接用pip3 install -r requirements.txt,遇到编译错误:

      gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPSUTIL_POSIX=1 -DPSUTIL_VERSION=565 -DPSUTIL_LINUX=1 -I/usr/include/python3.6m -c psutil/_psutil_common.c -obuild/temp.linux-x86_64-3.6/psutil/_psutil_common.o
      psutil/_psutil_common.c:9:20: 致命错误:Python.h:没有那个文件或目录
       #include <Python.h>
                        ^
      编译中断。
      error: command 'gcc' failed with exit status 1
  • 谷歌了一下,发现缺少python-devel的包(Ubuntu下叫python-dev)

    # yum -y install python-devel
    已加载插件:fastestmirror
    Loading mirror speeds from cached hostfile
    \* base: repos-lax.psychz.net
    \* elrepo-kernel: repos.lax-noc.com
    \* epel: d2lzkl7pfhq30w.cloudfront.net
    \* extras: mirror.scalabledns.com
    \* updates: mirror.scalabledns.com
    软件包 python-devel-2.7.5-86.el7.x86_64 已安装并且是最新版本
    无须任何处理

???,啥情况,这不是已经安装上了吗?

我又谷歌了一下,发现Python2跟Python3使用的python-devel还不是同一个东西,Python3.4对应的叫python34-devel,Python3.6对应的叫python36-devel,安装之。

这下使用PIP安装依赖库没有问题了。

重启面板/etc/init.d/bt 3,终于启动了。

  • 防火墙设置
    貌似使用宝塔自带修复工具会关掉防火墙,开启之。

    # systemctl enable firewalld
    # systemctl start firewalld
  • 粗略检查了一下,应该没有其他问题了,算是手动修复了吧

后记

根据错误来看可能是宝塔默认使用的Python2被换成了Python3,然后缺了一坨依赖库,但是我好像也没改啊?总之最后确实是修复了宝塔面板。

批量装Python依赖前一定要检查列表
批量装Python依赖前一定要检查列表
批量装Python依赖前一定要检查列表

安装可能引起冲突的依赖一定要使用虚拟Python环境
安装可能引起冲突的依赖一定要使用虚拟Python环境
安装可能引起冲突的依赖一定要使用虚拟Python环境

最后修改:2020 年 05 月 08 日
Null