July 3, 2019 · Linux Python

系统升级后重新配置 Python venv

服务器系统从 Debian 9 Stretch 升级 Debian 10 Buster 后,跑着的小程序突然挂了,无法启动。查看日志如下:

Current thread 0x00007fbe8c848740 (most recent call first):
Could not find platform independent libraries
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to [:<exec_prefix>]
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'

应该是系统升级后,程序运行的 venv 还是老版本系统的配置,找不到正确的运行环境。

删除 venv ,重新建立 venv ,恢复环境,运行,OK。

rm -rf venv
pip install virtualenv
~/.local/bin/virtualenv venv
source venv/bin/activate
pip install -r requirements.txt
python start.py
Comments powered by Disqus