lib.im

解决宝塔面板升级后因Python2.7与Python3.6共存启动失败
问题描述起因是更新了宝塔6.9.9,重启之后面板打不开了,于是尝试修复面板,重装面板,最终都是报错。错误记录如下:...
扫描右侧二维码阅读全文
06
2019/09

解决宝塔面板升级后因Python2.7与Python3.6共存启动失败

问题描述

起因是更新了宝塔6.9.9,重启之后面板打不开了,于是尝试修复面板,重装面板,最终都是报错。
错误记录如下:

Starting Bt-Panel..........failed
------------------------------------------------------

[Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/gunicorn/util.py", line 135, in load_class
    mod = import_module('.'.join(components))
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'geventwebsocket'
]

------------------------------------------------------
Error: BT-Panel service startup failed.
        done

查看pythonpip默认版本,发现正常:

root@sever:~# python -V
Python 2.7.13
root@sever:~# pip -V
pip 19.2.3 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)
root@sever:~# 

但是还是使用了官方论坛提供的重建软连接方法,结果无效。

修复

由于官方论坛的机制是回帖还要审核,等了半天没有反应,于是自己尝试修复。
看错误提示应该是gunicorn默认使用python3.6运行了,小白并不会python,所以之能按一般思路走如下

尝试使用pip安装gunicorn

root@sever:~# pip install gunicorn

发现已经安装

Looking in indexes: https://mirrors.aliyun.com/pypi/simple
Requirement already satisfied: gunicorn in /usr/local/lib/python2.7/dist-packages (19.0.0)

尝试卸载pip3下的gunicorn

root@sever:~# pip3 uninstall gunicorn
Uninstalling gunicorn-19.9.0:
  Would remove:
    /usr/local/bin/gunicorn
    /usr/local/bin/gunicorn_paster
    /usr/local/lib/python3.6/site-packages/gunicorn-19.9.0.dist-info/*
    /usr/local/lib/python3.6/site-packages/gunicorn/*
Proceed (y/n)? y
  Successfully uninstalled gunicorn-19.9.0

尝试启动宝塔,报错改变:

Starting Bt-Panel./etc/init.d/bt:行27: gunicorn: 未找到命令
.........failed
------------------------------------------------------

[Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/gunicorn/util.py", line 135, in load_class
    mod = import_module('.'.join(components))
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'geventwebsocket'
]

------------------------------------------------------
Error: BT-Panel service startup failed.

未找到命令证明关联的是python3.6下的gunicorn,并不会自动关联到python2.7下的,

尝试卸载pipgunicorn

root@sever:~# pip uninstall gunicorn
Uninstalling gunicorn-19.0.0:
  Would remove:
    /usr/local/bin/gunicorn_django
    /usr/local/lib/python2.7/dist-packages/gunicorn-19.0.0.dist-info/*
    /usr/local/lib/python2.7/dist-packages/gunicorn/*
Proceed (y/n)? y
  Successfully uninstalled gunicorn-19.0.0

然后pip重装gunicorn

root@sever:~# pip install gunicorn
Looking in indexes: https://mirrors.aliyun.com/pypi/simple
Collecting gunicorn
  Downloading https://mirrors.aliyun.com/pypi/packages/8c/da/b8dd8deb741bff556db53902d4706774c8e1e67265f69528c14c003644e6/gunicorn-19.9.0-py2.py3-none-any.whl (112kB)
     |████████████████████████████████| 122kB 7.9MB/s 
Installing collected packages: gunicorn
Successfully installed gunicorn-19.9.0

再次尝试启动宝塔:

root@sever:~# bt
===============宝塔面板命令行==================
(1) 重启面板服务           (8) 改面板端口
(2) 停止面板服务           (9) 清除面板缓存
(3) 启动面板服务           (10) 清除登录限制
(4) 重载面板服务           (11) 取消入口限制
(5) 修改面板密码           (12) 取消域名绑定限制
(6) 修改面板用户名         (13) 取消IP访问限制
(7) 强制修改MySQL密码      (14) 查看面板默认信息
(22) 显示面板错误日志      (15) 清理系统垃圾
(23) 关闭BasicAuth认证     (16) 修复面板(检查错误并更新面板文件到最新版)
(0) 取消                   (17) 设置日志切割是否压缩
===============================================
请输入命令编号:1
===============================================
正在执行(1)...
===============================================
Stopping Bt-Tasks...    done
Stopping Bt-Panel...    done
Starting Bt-Panel.......        done
Starting Bt-Tasks...    done

启动成功

后记

小白什么也不懂,只能一步步推理,幸好最后解决了问题。

Last modification:September 6th, 2019 at 08:26 pm
如果觉得我的文章对你有用,请随意赞赏

Leave a Comment