我有一台服务器,该服务器的 python3 安装已损坏,位于只能通过 ssh 访问的远程位置。
我搜索过的大多数解决方案最终都归结为重新安装操作系统。更简单的命令如下
apt-get --reinstall install ubuntu-server
ModuleNotFoundError: No module named ...
失败并出现以下错误
Preparing to unpack .../dpkg_1.19.7ubuntu3_amd64.deb ...
Unpacking dpkg (1.19.7ubuntu3) over (1.19.7ubuntu3) ...
Setting up dpkg (1.19.7ubuntu3) ...
Selecting previously unselected package python3.8-minimal.
(Reading database ... 112481 files and directories currently installed.)
Preparing to unpack .../python3.8-minimal_3.8.5-1~20.04_amd64.deb ...
Unpacking python3.8-minimal (3.8.5-1~20.04) ...
Setting up python3.8-minimal (3.8.5-1~20.04) ...
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Python path configuration:
PYTHONHOME = (not set)
PYTHONPATH = (not set)
program name = '/usr/bin/python3.8'
isolated = 0
environment = 0
user site = 1
import site = 0
sys._base_executable = '/usr/bin/python3.8'
sys.base_prefix = '/usr'
sys.base_exec_prefix = '/usr'
sys.executable = '/usr/bin/python3.8'
sys.prefix = '/usr'
sys.exec_prefix = '/usr'
sys.path = [
'/usr/lib/python38.zip',
'/usr/lib/python3.8',
'/usr/lib/lib-dynload',
]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007f862a82a740 (most recent call first):
<no Python frame>
dpkg: error processing package python3.8-minimal (--configure):
installed python3.8-minimal package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
python3.8-minimal
E: Sub-process /usr/bin/dpkg returned an error code (1)
我被难住了。有人能建议修复损坏的 python3 吗?
答案1
易于无法帮助您,因为它需要损坏的 Python 3。
软件包不需要 Python 3,因此您可以使用它来重新安装 Python 3。但是,它不会自动处理依赖项,因此您必须按照有效的顺序安装它们。
python3
在中搜索适合您的发行版https://packages.ubuntu.com/例如,对于 focal (Ubuntu 20.04),只需单击几下即可进入软件包页面:https://packages.ubuntu.com/focal/python3
该页面用红色项目符号列出了其他哪些软件包依赖项和
python3
应该先安装。在此示例中python3.8-minimal
python3-minimal
libpython3-stdlib
它看起来像这样:
单击这些依赖项的名称,然后下载适用于您的计算机架构的 deb 文件。这是您执行此操作的区域:
安装你下载的 deb 文件
sudo dpkg -i [package name].deb
如果您尝试不同的安装顺序或者缺少其他依赖项,dpkg 将抛出错误。
不要忘记在安装依赖项之后完成 Python 3 主包的安装(第 2 点)。
您可以选择
sudo dpkg -a --configure
检查所有包裹是否确实有序。修复 Python 3 后,apt 应该可以再次工作。